sdk - Stop a corona collision event from firing multiple times -


so want collision listener fire once. i've tried putting in if execute variables it's not elegant.

local function collideground( self, event )          local obj  = event.other          local phase = event.phase                 if ( phase == "began" )                          if obj == ground                 print("hit")              end          elseif ( phase == "ended" )            end         return true     end     player.collision = collideground     player:addeventlistener( "collision", player )       

collision listener not touch event or tap event. whenever player object awakes collision event, collideground called , that's why provided 3 different event.phase.

any collision event handler returns true stop further propagation of collision event, if there further listeners otherwise have received it. allows further limit number of events created , passed lua side. while individual events not expensive, large numbers of them can affect overall performance, limiting event propagation practice.

i think collision detection somehow achieve goal. 😉


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -