我有一个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)
希望有人能指出我正确的方向!