Hi there pros!
I am in the first stage of my game and have started out with the control of movement and change of sprite sequences - depending on the direction the character is moving.
A touch on the screen makes the character fly, and a drag makes him move to that direction. And if you drag to the opposite, he turns and flies at the other direction. This involves three animations.
So, we start with the first codeblock where I check to see in what direction the player wants the character to fly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | local function getSpriteSeq(event) SPRITE_STATE = event.sprite.sequence end Runtime:addEventListener("touch", moveforward) local function moveforward( event) --> Save startposition when dragging if(event.phase=="began") then x0 = event.x end --> Check what direction we are going for... if(event.phase=="moved") then if not (player==nil) then if(x0 < event.x) then --> Flying forward player:applyLinearImpulse(.02, 0, player.x, player.y) if(SPRITE_STATE=="fly_left") then display.getCurrentStage():setFocus(nil) player:prepare("turn_right") player:play() end else --> Flying backward player:applyLinearImpulse(-.02, 0, player.x, player.y) if(SPRITE_STATE=="fly_right") then display.getCurrentStage():setFocus(nil) player:prepare("turn_left") player:play() end end end end display.getCurrentStage():setFocus( nil ) end |