Ok,
to have the animation(go up):
transition.to( character, { time=1500, xScale=1.5,yScale=1.5,transition=easing.continuousLoop})--add a listener to detect when the player is back on the ground(transition support on finish transition listener isJumping=true
move in any direction :
local movingX=0 local movingY=0 -- add button who move the player. For example with a joystick, movingX can go from -1 to 1 and for y too -- and to add inertie if the joystick is it in up position for more than 1 second the movingY go to 2. local myListener = function( event ) print( "Listener called with event of type " .. event.name ) --this happen every new display frame local nextX=character.x+movingX local nextY=character.y+movingY if(canIgoHere(nextX,nextY))then character:translate(movingX,movingY) end end Runtime:addEventListener( "enterFrame", myListener )
If you have tiled map, you can have in a table all data about area:
local myMap={} for(i=0,10)do -- initilisation for(j=0,10)do myMap[i][j]=0 end end myMap[0][0]=1-- walking tile myMap[0][1]=2-- walking and jumping area myMap[0][2]=3-- jumping tile -- that assume that the character can't go anywhere else -- obstacle detection, on which tile the character is : theXtile=math.floor(character.x/100) -- for example each tile is 100 pixel of width theYtile=math.floor(character.y/100) -- to know if the player can jump function canIJump() if(myMap[theXtile][theYtile]==2 or myMap[theXtile][theYtile]==3) jumpIsPossible=true return true else jumpIsPossible=false return false end end function canIgoHere(x,y) if(isJumping==false) then if(myMap[math.floor(x/100)][math.floor(y/100)]==1 or myMap[math.floor(x/100)][math.floor(y/100)]==2) then return true else return false end else if(myMap[math.floor(x/100)][math.floor(y/100)]==2 or myMap[math.floor(x/100)][math.floor(y/100)]==3) then end end
do you get the idea of how to make it? for information you can create automatically the myMap array if you code a few dozen of code line
there is a lot of way to do it, if you need another way I can do it for you