我有一个SKSpriteNode,我想在用户触摸屏幕时更改它的纹理.但无法弄清楚如何做到这一点.
创建和添加头部.(在标题中声明).
head = [SKSpriteNode spriteNodeWithImageNamed:[NSString stringWithFormat:@"%@",face]];
head.position = CGPointMake(size.width / 2, size.height / 2);
[self addChild:head];
Run Code Online (Sandbox Code Playgroud)
检测到触摸时,会运行以下内容,但我无法确定如何将其应用到SKSpritenode?!
SKAction* changeFace = [SKAction setTexture:[SKTexture textureWithImageNamed:[NSString stringWithFormat:@"%@",face]]];
[self runAction:changeFace];
Run Code Online (Sandbox Code Playgroud)
我也尝试了以下,但它似乎没有工作......
head.texture = [SKTexture textureWithImageNamed:[NSString stringWithFormat:@"%@",face]];
Run Code Online (Sandbox Code Playgroud)
希望有人能指出我正确的方向!
Six*_*oot 15
看起来你正在尝试在场景上运行动作(或者除了你的精灵之外的任何其他对象.)但是第二个代码应该可以工作,但是使用SKAction会尝试使用它.
[head runAction:changeFace];
Run Code Online (Sandbox Code Playgroud)
Dan*_*ima 11
我在这里工作,看看下面的代码:
1 - 创建SKSpriteNode
self.ninja = [SKSpriteNode spriteNodeWithImageNamed:@"ninja1"];
self.ninja.position = CGPointMake(self.ninja.size.width/2, self.frame.size.height/2);
[self addChild:self.ninja];
Run Code Online (Sandbox Code Playgroud)
2 - 更改纹理:
self.ninja.texture = [SKTexture textureWithImageNamed:@"ninja2"];
Run Code Online (Sandbox Code Playgroud)
Obs:我在touchesBegan事件中更改纹理,但这应该以您想要的任何方式工作.
| 归档时间: |
|
| 查看次数: |
11013 次 |
| 最近记录: |