У меня есть кнопка создать в сцене, как это:Как я могу создать функциональную анимированную кнопку?
self.playButton = [SKSpriteNode spriteWithImageNamed:@"playbutton.png"];
self.playButton.size = CGSizeMake(100,100);
self.playButton.position = CGPointMake(CGRectGetMidX(self.frame), 100);
[self addChild:self.playButton];
Тогда в touchesBegan:
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
if([self.playButton containsPoint:location]){
self.playButton.texture = [SKTexture textureWithImageNamed:@"playbuttonpressed.png"];
[self.playButton runAction: [self touchButtonAction]];
}
Тогда в touchesEnded:
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
if([self.playButton containsPoint:location]){
self.playButton.texture = [SKTexture textureWithImageNamed:@"playbutton.png"];
[self.view presentScene:self.nextScene transition:self.sceneTransition];
}
Тогда в touchButtonAction:
SKAction *toSmall = [SKAction scaleBy:0.8 duration:0.1];
return toSmall;
Вот проблема: Когда я нажимаю кнопку, touchsEnded вызывается до того, как действие закончено, что приводит к неполной анимации, которая не выглядит хорошо (кажется, лагги). Как я могу сделать кнопку, которая заканчивает анимацию перед переходом?
Попробуйте AGSpriteButton. По умолчанию она реализует ту же анимацию. https://github.com/akashgupta88/AGSpriteButton – ZeMoon