Hi guys,
Just wanted to ask a quick question. I was wondering if this is the right way or not.
I am trying to create random movement of a sprite in a screen. To do this I call "startRandomMovement" which creates an action and recursively calls itself. IS it ok as I will be creating a lot of actions in runtime?
[code]
-(void) startRandomMovement{
int xPosition = rand() % 480;
int yPosition = rand() % 320;
NSLog(@"xPosition: %i, yPosition: %i", xPosition, yPosition);
id action = [Sequence actions:
[MoveBy actionWithDuration:2 position:ccp(xPosition,yPosition)],
[CallFunc actionWithTarget:self selector:@selector(startRandomMovement)],
nil];
[self runAction:action];
}
[/code]
One more quick question. The xPosition and yPosition seems to take the sprite off the screen after some moves. The move action seems to move the sprite relative to its position rather then the actual x,y position of the screen. How do I keep the sprite in the screen boundaries?
Thanks for the help!