在我的游戏中,我沿着相同的cgpath移动了许多skspritenode:
[SKAction followPath:APath asOffset:NO orientToPath:YES duration:68]
如果我在场景中添加所有我的skpritenode同时它们在跟踪路径动画期间重叠,所以我必须添加每个精灵有一些延迟...这样精灵不能重叠但在游戏中我有“抖动“每次我有这个精灵之一。我使用这样的东西:
SKAction *InsertSpriteAction=[SKAction repeatActionForever:[SKAction sequence:@[[SKAction performSelector:@selector(AddSprite) onTarget:self],[SKAction waitForDuration:0.5]]]];
并添加精灵:
-(void)AddSprite{
if (NumberofSprite<50) {
SKSpriteNode *Sprite=[SKSpriteNode spriteNodeWithImageNamed:@"sprite.png"];
Sprite.size=CGSizeMake(8, 8);
Sprite.position=CGPointMake(1320, 570);
[_worldNode addChild:Sprite];
NSMutableArray *textures = [NSMutableArray arrayWithCapacity:10];
for (int i = 1; i < 10; i++) {
NSString *textureName =
[NSString stringWithFormat:@"sprite%i", i];
SKTexture *texture =[SKTexture textureWithImageNamed:textureName];
[textures addObject:texture];
}
SKAction *spriteAnimation = [SKAction animateWithTextures:textures timePerFrame:0.2];
SKAction *repeat = [SKAction repeatActionForever:spriteAnimation];
[Sprite runAction:repeat];
[Sprite runAction: [SKAction repeatActionForever:[SKAction followPath:APath asOffset:NO orientToPath:YES duration:68]]];
NumberofSprite++;
}
else{
[self removeActionForKey:@"addingsprites"];
}
}
我如何在路径的不同点开始我的精灵?在同一路径中有许多起始点,我可以在级别加载期间立即添加所有精灵,并启动一个没有重叠的跟随路径......