相关疑难解决方法(0)

将 SKAction 添加到 Sprite 队列中,依次运行

我听触摸并将 SKAction 添加到精灵。如果现有操作尚未完成,我希望将操作添加到队列中,以便它一个接一个地执行。有没有类似的设计经验?

我确实使用了数组和块。如果有更简单的方法吗?

@interface GAPMyScene()
@property(strong,nonatomic)SKSpriteNode*ufo;
@property(strong,nonatomic)NSMutableArray*animationQueue;
@property(copy,nonatomic)void(^completeMove)();
@end

@implementation GAPMyScene

-(id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {
        self.ufo = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];
        self.animationQueue = [[NSMutableArray alloc] init];
        __unsafe_unretained typeof(self) weakSelf = self;
        self.completeMove = ^(void){
            [weakSelf.ufo runAction:[SKAction sequence:[weakSelf.animationQueue copy]] completion:weakSelf.completeMove];
            NSLog(@"removeing %@", weakSelf.animationQueue);
            [weakSelf.animationQueue removeAllObjects];
        };
        [self addChild:self.ufo];
    }
    return self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];
        SKAction*moveAnimation = [SKAction moveTo:location duration:2];
        if (![self.ufo hasActions]) {
            [self.ufo …
Run Code Online (Sandbox Code Playgroud)

objective-c sprite-kit skaction

5
推荐指数
1
解决办法
1555
查看次数

标签 统计

objective-c ×1

skaction ×1

sprite-kit ×1