【问题标题】:MyScene won't perform ActionMyScene 不会执行操作
【发布时间】:2014-09-11 20:02:30
【问题描述】:

我想对我的游戏标题执行一个简单的操作(放大/缩小序列永远重复),但由于某种原因,当我调用方法“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]];
}

【问题讨论】:

    标签: objective-c animation sprite-kit skaction


    【解决方案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];}
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      • 2020-07-11
      • 2021-06-18
      相关资源
      最近更新 更多