简体   繁体   English

精灵套件-如何移动精灵?

[英]Sprite kit - How to move a sprite?

I have some code which adds sprites at random intervals but now i want every new sprite added to move across the screen. 我有一些代码以随机的间隔添加子画面,但现在我希望添加的每个新子画面在屏幕上移动。 This is what i have : 这就是我所拥有的:

-(void)createRat {

CGPoint startPoint = CGPointMake(120, 298);// those coordinates are the bottom left corner

SKSpriteNode *rat = [SKSpriteNode spriteNodeWithImageNamed:@"rat"];
rat.position = CGPointMake(startPoint.x, startPoint.y);
rat.zPosition = 6;
[rat setScale:0.5f];
[self addChild:rat];

// we now want to call this method again repeatedly at a random interval :)

float randomNum = arc4random_uniform(3)+3;
[self performSelector:@selector(createRat) withObject:nil afterDelay:randomNum];

}

???? ????

You can add action to every sprite to make them moving, eg 您可以向每个精灵添加动作以使其移动,例如

SKAction *moveNodeUp = [SKAction moveByX:0.0 y:100.0 duration:1.0];
[rocketNode runAction: moveNodeUp];

And I suggest you having a look at the apple 's documentation https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/AddingActionstoSprites/AddingActionstoSprites.html#//apple_ref/doc/uid/TP40013043-CH11-SW1 我建议您看看苹果的文档https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/AddingActionstoSprites/AddingActionstoSprites.html#//apple_ref/doc/uid/TP40013043 -CH11-SW1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM