I want to perform a simple action on my Game title (zoom in/zoom out-sequence that repeats forever), but for some reason it does not work when I call the method "ZoomSequence". What is the problem with my code?
#import <SpriteKit/SpriteKit.h>
#import <AVFoundation/AVFoundation.h>
@interface MyScene : SKScene
@property (strong, nonatomic) SKLabelNode *mainTitle;
@end
#import "MyScene.h"
@implementation MyScene
@synthesize mainTitle;
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
SKSpriteNode *background = [[SKSpriteNode alloc] initWithImageNamed:@"bg.png"];
background.anchorPoint = CGPointMake(0, 0);
background.zPosition = 1;
[self addChild: background];
SKLabelNode *title = [SKLabelNode labelNodeWithFontNamed:@"Verdana-BoldItalic"];
title.fontSize = 45;
title.text = @"Game Title";
title.position = CGPointMake(260, 250);
title.zPosition = 3;
self.mainTitle = title;
[self addChild:title];
[self ZoomSequence];
}
return self;
}
-(void)ZoomSequence{
SKAction *HUDzoom = [SKAction scaleTo:2.0 duration:2];
SKAction *HUDzoomOut = [SKAction scaleTo:1.0 duration:2];
SKAction *HUDAnimation = [SKAction sequence:@[HUDzoom, HUDzoomOut]];
[self.mainTitle runAction:[SKAction repeatActionForever:HUDAnimation]];
}
Fixed it. It needed one touch on the Screen for the action to start, but I did not notice that, because my Level1-Scene was always opened on the first touch and MyScene was dismissed:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
SKScene *firstLevel = [[Level_1 alloc] initWithSize:self.size];
[self.view presentScene: firstLevel];
}
so I modified my method like this:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (firstTouch == YES){
firstTouch = NO;
}else if (firstTouch == NO){
SKScene *restart = [[Level_1 alloc] initWithSize:self.size];
[self.view presentScene:restart];}
}