objective-c – 如何在iOS中切片切割精灵(核心图形)

objective-c – 如何在iOS中切片切割精灵(核心图形),第1张

概述我正在开发一款游戏,我想在其中添加一个合适的切片功能..所以当精灵切片时,应该创建2个新的精灵..请检查 here 目前,我只是缩小尺寸并复制精灵..这样的东西..在此先感谢.. - (BOOL) sliceSprite: (Sprite *) sprite withPath: (UIBezierPath *) slicePath { CGSize size = s 我正在开发一款游戏,我想在其中添加一个合适的切片功能..所以当精灵切片时,应该创建2个新的精灵..请检查 here

目前,我只是缩小尺寸并复制精灵..这样的东西..在此先感谢..

- (BOol) sliceSprite: (Sprite *) sprite withPath: (UIBezIErPath *) slicePath {            CGSize size = sprite.size;            size.wIDth /= 2;             size.height /=2;            sprite.size = size;            sprite.sliced = YES;            Sprite *newSprite = [[Sprite alloc] initWithImage: sprite.image];            newSprite.position = sprite.position;            newSprite.size = size;            newSprite.sliced = YES;            newSprite.inVIEw = YES;            newSprite.xVeLocity = SliCE_SPEEDUP * sprite.yVeLocity;            newSprite.yVeLocity = SliCE_SPEEDUP * sprite.xVeLocity;            newSprite.angularVeLocity = -SliCE_REVUP * sprite.angularVeLocity;            [Sprites addobject: newSprite];            [newSprite release];        sprite.angularVeLocity = SliCE_REVUP * sprite.angularVeLocity;            sprite.xVeLocity = -SliCE_SPEEDUP * sprite.xVeLocity;            sprite.yVeLocity = -SliCE_SPEEDUP * sprite.yVeLocity;            return YES;    }- (voID) sliceSpritesInSwipePath{    CGRect swipeRect = [swipePath bounds];        for (NSUInteger i = 0; i < [Sprites count]; i++)        {                Sprite *sprite = [Sprites objectAtIndex: i];                if ([sprite intersectsWithPathInArray: swipePoints                                               inRect: swipeRect])                        if ([self sliceSprite: sprite withPath: swipePath])                        {                                [self resetSwipe];                                if (![sliceSound isPlaying])                                        [sliceSound play];                break;                        }        }

}

解决方法 既然你在这里使用CoreGraphics,为什么不在绘制精灵时简单地使用剪切路径呢?

复制要切片的精灵,然后应用将两半遮盖的简单多边形作为各自的剪切路径.您需要的功能称为CGContextClip,可以找到简短的教程here.

编辑:教程列出了这个例子:

CGContextBeginPath (context);CGContextAddArc (context,w/2,h/2,((w>h) ? h : w)/2,2*PI,0);CGContextClosePath (context);CGContextClip (context);

这会将当前路径设置为圆,然后将当前路径应用为剪切区域.

总结

以上是内存溢出为你收集整理的objective-c – 如何在iOS中切片/切割精灵(核心图形)全部内容,希望文章能够帮你解决objective-c – 如何在iOS中切片/切割精灵(核心图形)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1226201.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存