How to make a object move randomly like the pocket frog , is there any example like that ?
https://itunes.apple.com/us/app/pocket-frogs/id386644958?mt=8
How to make a object move randomly like the pocket frog , is there any example like that ?
https://itunes.apple.com/us/app/pocket-frogs/id386644958?mt=8
Depends how you want it to behave. I don’t know this game, what do you actually want your actors to do ?
You can check out this 4-part tutorial for one way to make random movements.
I want to make some object move randomly when the object greater than screen area it will change the direction and move again .
https://www.youtube.com/watch?v=o207VkP_zBc
like the frog in this game
Well it looks to me like they are just randomly moving a set distance.
So what you need to do is something like:
function jumpFrog(frog) local newX,newY repeat newX = frog.X + math.random(-100,100) newY = frog.Y + math.random(-100,100) until newX \> 0 and newY \> 0 and newX \< display.contentWidth and newY \< display.contentHeight transition.to(frog, { time = math.random(1000,2000), x = newX, y = newY, onComplete = doSomething }) end
Note, untested, I have just typed this off my head without looking at anything, but you get the idea
Basically, for the frog, it calculates the next jump point, which is any point 100 pixels away from where it is now, and keeps going until it is on the screen, then it transitions to that position over a period of 1-2 seconds.
One of the easings will make it look like a jump, probably
If you use atan2 on the x and y offsets and convert it back to degrees that should allow you to align the sprite so it is ‘looking’ the right way.
You could also rather than randomly calculate dx,dy calculate the angle and distance and use trigonometry to work out the new location, this might actually be easier now I come to think about it.
Depends how you want it to behave. I don’t know this game, what do you actually want your actors to do ?
You can check out this 4-part tutorial for one way to make random movements.
I want to make some object move randomly when the object greater than screen area it will change the direction and move again .
https://www.youtube.com/watch?v=o207VkP_zBc
like the frog in this game
Well it looks to me like they are just randomly moving a set distance.
So what you need to do is something like:
function jumpFrog(frog) local newX,newY repeat newX = frog.X + math.random(-100,100) newY = frog.Y + math.random(-100,100) until newX \> 0 and newY \> 0 and newX \< display.contentWidth and newY \< display.contentHeight transition.to(frog, { time = math.random(1000,2000), x = newX, y = newY, onComplete = doSomething }) end
Note, untested, I have just typed this off my head without looking at anything, but you get the idea
Basically, for the frog, it calculates the next jump point, which is any point 100 pixels away from where it is now, and keeps going until it is on the screen, then it transitions to that position over a period of 1-2 seconds.
One of the easings will make it look like a jump, probably
If you use atan2 on the x and y offsets and convert it back to degrees that should allow you to align the sprite so it is ‘looking’ the right way.
You could also rather than randomly calculate dx,dy calculate the angle and distance and use trigonometry to work out the new location, this might actually be easier now I come to think about it.