gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:00:29 25 4
gpt4 key购买 nike

在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com