How to rotate an SKSpriteNode around the node's Y-axis?

后端 未结 4 2041
执笔经年
执笔经年 2020-12-28 20:37

I\'m trying to rotate an SKSpriteNode node around it\'s Y-axis. I know there\'s the zRotation property and that will rotate the node clockwise or counter-clockwise; however,

4条回答
  •  半阙折子戏
    2020-12-28 21:31

        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];
        sprite.position = location;
        SKAction* action0 = [SKAction scaleXTo:1.0 duration:0.5];
        SKAction* action1 = [SKAction scaleXTo:0.1 duration:0.5];
        SKAction* action2 = [SKAction scaleXTo:-0.1 duration:0.5];
        SKAction* action3 = [SKAction scaleXTo:-1.0 duration:0.5];
    
        SKAction* action = [SKAction sequence:@[action0, action1, action2, action3]];
        [sprite runAction:[SKAction repeatActionForever:action]];
    
        [self addChild:sprite];
    

    This will get you what looks like a 3D card flip, but obviously if you're expecting an object to have depth you wont get that programatically with scaling.

    Or well less animations (As LearnCocos2D suggested):

        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];
        sprite.position = location;
        SKAction* action0 = [SKAction scaleXTo:1.0 duration:0.5];
        SKAction* action1 = [SKAction scaleXTo:-1.0 duration:0.5];
    
        SKAction* action = [SKAction sequence:@[action0, action1]];
        [sprite runAction:[SKAction repeatActionForever:action]];
    
        [self addChild:sprite];
    

提交回复
热议问题