我正在开发一款游戏,我想在其中添加一个适当的切片功能。所以当一个 Sprite 被切片时,应该创建 2 个新的 Sprite 。请检查 here
目前,我只是缩小尺寸并复制 Sprite 。类似这样的东西。提前致谢。
- (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;
}
}
最佳答案
是否需要具体的分割线? Fruit Ninja 只会生成两半的水果,就好像它被从中间切开一样,这很容易做到:
- 创建两个宽度为原始 Sprite 宽度一半的 Sprite
- 将它们放置在原始 Sprite 水平中心线的 1/4 和 3/4 处
- 添加旋转/加速等
- 修改纹理坐标,使左 Sprite 具有纹理的左半部分,右 Sprite 具有纹理的右半部分。
关于objective-c - 如何在 iOS 中切片/剪切 Sprite (Core Graphics),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12234626/