ios - Sprite-Kit 中的按钮按下动画

标签 ios animation button sprite-kit

在 Sprite-Kit 游戏中,我想在按下按钮时为其设置动画。现在代码直接使用react,而不是等到动画执行。此外,当用户将手指从按钮上擦出时,我希望按钮能够动画回来。

Here my code:

-(void)addStartButton:(CGSize)size {
    self.start = [SKSpriteNode spriteNodeWithImageNamed:@"startButton1"];
    self.start.position = CGPointMake(size.width/2, size.height/2);
    self.start.name = @"start";
    [self addChild:self.start];  
}



-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {


   UITouch *touch = [touches anyObject];
   CGPoint location = [touch locationInNode:self];
   SKNode *node = [self nodeAtPoint:location];


if ([node.name isEqualToString:@"start"]) {

    self.start.texture = [SKTexture textureWithImageNamed:@"startButton2"];        

    MyScene *myScene = [MyScene sceneWithSize:self.size];
    [self.view presentScene:myScene transition:[SKTransition pushWithDirection:SKTransitionDirectionLeft duration:0.5]];
    }
}

最佳答案

在切换到另一个场景之前,这会给你 2 秒的延迟:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  
   UITouch *touch = [touches anyObject];
   CGPoint location = [touch locationInNode:self];
   SKNode *node = [self nodeAtPoint:location];    

if ([node.name isEqualToString:@"start"]) {
    SKAction *changeTexture = [SKAction runBlock:^{
        self.start.texture = [SKTexture textureWithImageNamed:@"startButton2"];   
    }];
    SKAction *wait = [SKAction waitForDuration:2.f];
    SKAction *presentAnotherScene = [SKAction runBlock:^{        
        MyScene *myScene = [MyScene sceneWithSize:self.size];
        [self.view presentScene:myScene transition:[SKTransition pushWithDirection:SKTransitionDirectionLeft duration:0.5]];
    }];
    [self runAction:[SKAction sequence:@[changeTexture,wait,presentAnotherScene]]];
    }
}

Furthermore I want the button to animate back when the user wipes his finger out of the button.



这似乎毫无意义,因为当用户按下按钮时您正在转换到另一个场景。

关于ios - Sprite-Kit 中的按钮按下动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23244869/

相关文章:

java - 墙壁上的 Pong 反射

javascript - 将自定义动画传递给组件

javascript - 使用 WebGL 和 three.js 的运动模糊

android - View 底部带有按钮的 Webview

android - 一个 ListActivity 和一个 Button : mission impossible?

ios - 如何将相机胶卷图像附加到邮件编辑器

ios - 插入符在 UI​​TextView 和 Text Kit 中的长按空白处消失

ios - libpng 错误 : CgBI: unhandled critical chunk xcode 7. 3

ios - UITableview swift 中的 UITextview 高度

android - 如何禁用返回、主页、多任务物理按钮?