使用touchesBegan镜像精灵?

时间:2014-08-14 21:18:37

标签: ios ios7 sprite-kit

这是我目前的代码:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    SKAction *moveNodeRight = [SKAction moveByX:-200.0 y:0.0 duration:0.7];
    [_squirrelSprite runAction: moveNodeRight withKey:@"changeside"];
}

当我点击屏幕时,我想让我当前的精灵镜像自己。如果没有办法镜像它,有没有办法在点击屏幕时更改精灵?

此外,当您再次点击屏幕时,我希望精灵返回到屏幕上的原始位置并翻转到原始精灵。我应该使用与此类似的代码来确定它应该采用哪种方式?谢谢!

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (isRightSide) {
        //Change to sprite's position to the LEFT side 
    } else {
    //Change to sprite's position to the RIGHT side 
    }
   isRightSide = !isRightSide;
}

1 个答案:

答案 0 :(得分:0)

水平镜像SKSpriteNode的纹理:

mySprite.xScale = -1.0;

要来回翻转,请在touchesBegan中使用此代码:

if(mySprite.xScale == -1.0)
{
    mySprite.xScale = 1.0;
} else {
    mySprite.xScale = -1.0;
}