gpt4 book ai didi

objective-c - 如何在 iOS 中切片/剪切 Sprite (Core Graphics)

转载 作者:可可西里 更新时间:2023-11-01 06:11:29 26 4
gpt4 key购买 nike

我正在开发一款游戏,我想在其中添加一个适当的切片功能。所以当一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com