我想对我的游戏标题执行一个简单的操作(放大/缩小序列,永远重复),但由于某种原因,当我调用方法“ZoomSequence”时它不起作用。我的代码有什么问题?
#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]];
}
答案 0 :(得分:1)
修正了它。它需要在屏幕上触摸一下才能开始动作,但我没有注意到,因为我的Level1-Scene总是在第一次触摸时打开并且MyScene被解雇了:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
SKScene *firstLevel = [[Level_1 alloc] initWithSize:self.size];
[self.view presentScene: firstLevel];
}
所以我修改了我的方法:
-(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];}
}