Hi,
So I have created a “frog jumping” sprite and I am trying to make it jump across the screen. Seems easy enough, however I am having a heck of a time getting it to work as I want.
Right now I have the following;
local function jumpUp() local params = { x = jumpingFrog.x - 60, y = jumpingFrog.y - 60, time = 350 } transition.to(jumpingFrog, params) end local function jumpDown() local params = { x = jumpingFrog.x - 60, y = jumpingFrog.y + 60, time = 350 } transition.to(jumpingFrog, params) end local function startJumping() jumpingFrog:play() local i = 1 while (i \< 5) do timer.performWithDelay(350, jumpUp,1) timer.performWithDelay(700, jumpDown,1) i = i + 1 end end
I have the sprite animating fine at 700ms. But I can’t seem to transition to the up and down repeatedly without just typing transition.to(…) and increase the time by 350 a bunch of times. Obviously in the while loop the delays all pretty much get ran at the same time and it is just running the first iteration of up and down. Is there a way to write a loop that allows this to happen multiple times or do I just have to program it to and increase the time (ex, 350, 700, 1050, 1400…).
Or is there something I am doing horribly wrong? BTW, I am currently not using any physics in the game, but am not opposed to it if it is required to get this to work.
-------UPDATED-----
This is how I got it working-ish, is there a better way?
local function jumpUp() local params = { x = jumpingFrog.x - 60, y = jumpingFrog.y - 60, time = 350 } transition.to(jumpingFrog, params) end local function jumpDown() local params = { x = jumpingFrog.x - 60, y = jumpingFrog.y + 60, time = 350 } transition.to(jumpingFrog, params) end local function startJumping() jumpingFrog:play() local i = 1 local delay = 350 while (i \< 5) do timer.performWithDelay(delay, jumpUp,1) delay = delay + 350 timer.performWithDelay(delay, jumpDown,1) delay = delay + 350 i = i + 1 end end