大佬教程收集整理的这篇文章主要介绍了objective-c – 如何在iOS中切片/切割精灵(核心图形),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
目前,我只是缩小尺寸并复制精灵..这样的东西..在此先感谢..
- (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; } }
}
复制要切片的精灵,然后应用将两半遮盖的简单多边形作为各自的剪切路径.您需要的功能称为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中切片/切割精灵(核心图形)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。