gpt4 book ai didi

ios - 如何在 spritekit 中更改 'touchbegan' 中的字符图像?

转载 作者:行者123 更新时间:2023-11-29 10:47:23 24 4
gpt4 key购买 nike

我目前正在使用 Sprite Kit 和 Xcode 设计游戏。我的角色通常处于运行状态,由两个图像组成-代码如下:

bobSKTexture* Texture1 = [SKTexture textureWithImageNamed:@"bob1"];
bobTexture1.filteringMode = SKTextureFilteringNearest;
SKTexture* bobTexture2 = [SKTexture textureWithImageNamed:@"bob2"];
bobTexture2.filteringMode = SKTextureFilteringNearest;

SKAction* run = [SKAction repeatActionForever:[SKAction animateWithTextures:@[birdTexture1, birdTexture2] timePerFrame:0.2]];

_bob = [SKSpriteNode spriteNodeWithTexture:birdTexture1];
[_bob setScale:2.0];
_bob.position = CGPointMake(self.frame.size.width / 4, CGRectGetMidY(self.frame));
[_bob runAction:run];

我希望图像在触摸屏幕时发生变化,只持续很短的时间,然后我希望它返回到上面的代码。我怎样才能做到这一点?

最佳答案

正如 Jānis K 所说,当您想要更改图像时,这样做会更容易:

[_bob removeAllActions];
_bob.texture = [SKTexture textureWithImageNamed:NEW_TEXTURE];
[self performSelector:@selector(resetAnimation) withObject:nil afterDelay:2.0f];

NEW_TEXTURE 是您希望它更改为的纹理/图像的名称。

self 将是场景或您调用代码制作 _bob

的任何地方

这是 resetAnimation 方法,在您的场景中或您调用代码的任何地方定义 _bob:

- (void)resetAnimation
{
SKAction* run = [SKAction repeatActionForever:[SKAction animateWithTextures:@[birdTexture1, birdTexture2] timePerFrame:0.2]];
[_bob runAction:run];
}

关于ios - 如何在 spritekit 中更改 'touchbegan' 中的字符图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21961891/

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