簡體   English   中英

精靈套件-如何移動精靈?

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

我有一些代碼以隨機的間隔添加子畫面,但現在我希望添加的每個新子畫面在屏幕上移動。 這就是我所擁有的:

-(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];

}

????

您可以向每個精靈添加動作以使其移動,例如

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

我建議您看看蘋果的文檔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