I have a draggable sprite in my project who’s state I want to change depending on whether it is moving upwards, rightwards, downwards, etc. If it is moving at an angle (upwards and rightwards, for example), I want whichever direction is greater to ‘win out’, meaning if it is moving upwards more than rightwards, it will display the ‘moving upwards state’.
Is there any way to create some sort of code like "if move.y > move.x then display “Player run up”? I’m not much of a coder, so I don’t know how to write this properly. Can anyone help? Peach, maybe?
What additional code do I have to add to the drag/onTouch function below:
local function onTouch( event ) local t = event.target local phase = event.phase if "began" == phase then -- Make target the top-most object local parent = t.parent parent:insert( t ) display.getCurrentStage():setFocus( t ) -- Spurious events can be sent to the target, e.g. the user presses -- elsewhere on the screen and then moves the finger over the target. -- To prevent this, we add this flag. Only when it's true will "move" -- events be sent to the target. t.isFocus = true -- Store initial position t.x0 = event.x - t.x t.y0 = event.y - t.y elseif t.isFocus then if "moved" == phase then -- Make object move (we subtract t.x0,t.y0 so that moves are -- relative to initial grab point, rather than object "snapping"). t.x = event.x - t.x0 t.y = event.y - t.y0 elseif "ended" == phase or "cancelled" == phase then display.getCurrentStage():setFocus( nil ) t.isFocus = false end end -- Important to return true. This tells the system that the event -- should not be propagated to listeners of any objects underneath. return trueend[/code]Thanks very much,Steven [import]uid: 79394 topic_id: 13139 reply_id: 313139[/import]
[import]uid: 71210 topic_id: 13139 reply_id: 48280[/import]