Created
September 17, 2012 22:58
-
-
Save jquave/3740295 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This creates random animations by changing the point on the screen the popout should be animating towards | |
*/ | |
- (void) changeTarget:(ccTime)dt { | |
if(isDragging || !isAnimatingRandomly) return; | |
// Create random movements | |
CGPoint p = self.position; | |
float destX = arc4random()%1024; | |
float destY = arc4random()%768; | |
float isOnX = arc4random()%100; | |
if(isOnX>50) { | |
// Put on X axis | |
if(arc4random()%100 > 50) | |
destY = self.boundingBox.size.height/2; // BOTTOM | |
else destY = 768-self.boundingBox.size.height/2; // TOP | |
} | |
else { | |
// Put on Y axis | |
if(arc4random()%100 > 50) | |
destX = self.boundingBox.size.width/2; | |
else | |
destX = 1024-self.boundingBox.size.width/2-100; // RIGHT | |
} | |
p.x = destX; | |
p.y = destY; | |
id randomMoveAction = [CCMoveTo actionWithDuration:8.0f position:CGPointMake(p.x,p.y)]; | |
[self runAction:randomMoveAction]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment