In the following code i want each object to have it’s own enterframe listener.
But the problem is that…
Runtime:addEventListener ( “enterFrame”, hitEnterFrame ) works!!!
obj:addEventListener ( “enterFrame”, hitEnterFrame ) doesn’t work!!!
local gotHit = function(obj, hit, d, s, f) if(s == "hit4" and obj.sequence ~= "hit2") then obj.ground = obj.y obj.gravityScale = 1 print (d) if(d == 1 or d == -1)then if(d \< 0) then obj:setLinearVelocity(100, -200) else obj:setLinearVelocity(-100, -200) end else if(d \< obj.x) then obj:setLinearVelocity(100, -200) else obj:setLinearVelocity(-100, -200) end end --obj:applyForce(15, -5, obj.x, obj.y) obj.gettingHit = hit obj:setSequence("hit3") --obj:setFrame(f) obj:play() audio.play(soundHit4) obj.health = obj.health - mediumHurt function hitEnterFrame(event) if(obj ~= nil and obj.ground ~= nil)then if (obj.y \>= obj.ground) then --print("obj.y \<= obj.ground") obj.y = obj.ground obj.gravityScale = 0 obj:setLinearVelocity(0, 0) Runtime:removeEventListener("enterFrame", hitEnterFrame) obj:setSequence( "hit4" ) obj:play() if(obj == player)then obj:addEventListener( "sprite", playerHitAnim ) end end else Runtime:removeEventListener("enterFrame", hitEnterFrame) end end Runtime:addEventListener ( "enterFrame", hitEnterFrame ) --obj:addEventListener ( "enterFrame", hitEnterFrame ) end
PS: this function achieves jump in zero gravity.