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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.