Lua Corona SDK Conflicting Event Listeners -


[solved] looking, figured out. needed un-nest return true statements in of if conditions.

i have started learning lua week, , have started program 2d side-scroller game using corona sdk. in game, player's character moved pressing buttons displayed on screen virtual game pad. these buttons work perfectly, however, problem have a

runtime:addeventlistener("tap", onscreentap) 

event listener calls shoot() function fire projectile player whenever tap registered. results in projectile firing every time lift touch 1 of movement buttons.

is there way can stop shoot function calling when finish touching 1 of movement keys? have tried

display.getcurrentstage:setfocus() 

and putting

return true  

at end of movement functions nothing seems work.

you can use basics in every touch function have.. or touch events. combining touch events in single function may solve problem.

function inbounds( event )     local bounds = event.target.contentbounds     if event.x > bounds.xmin , event.x < bounds.xmax , event.y > bounds.ymin , event.y  < bounds.ymax         return true     end     return false end    function touchhandler( event )     if event.phase == "began"         -- stuff here --         display.getcurrentstage():setfocus(event.target)         event.target.isfocus=true     elseif event.target.isfocus == true         if event.phase == "moved"             if inbounds( event )                 -- stuff here --             else                 -- stuff here --                 display.getcurrentstage():setfocus(nil)                 event.target.isfocus=false             end         elseif event.phase == "ended"             -- stuff here --             display.getcurrentstage():setfocus(nil)             event.target.isfocus=false         end     end     return true end 

by way, if try use in runtime, throw , error. can add event listener background or put control mechanisnms like

if event.target -- blah blah end 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -