whenever my touch event ended ,my object doesnt stop moving.
here is my code:
local physics=require(“physics”)
physics.start();
physics.setGravity(0,0);
local wall=display.newImageRect(“c.png”,200,100);
wall.x=200;
wall.y=250;
physics.addBody(wall);
wall.myName=“wall”;
local function active(self,event)
self:applyForce(0,-1.5,self.x,self.y);
end
local function touchscreen( event )
local wall=event.target;
local id = event.id
local phase=event.phase;
if (“began”==phase)then
--set touch focus on the wall
display.currentStage:setFocus(wall,id);
wall.isFocus = true
wall.enterFrame = active
Runtime:addEventListener(“enterFrame”,wall)
elseif( wall.isFocus ) then
if( phase == “ended” ) then
display.currentStage:setFocus( wall, nil )
wall.isFocus = false
Runtime:removeEventListener(“enterFrame”,wall)
end
end
return true;
end
wall:addEventListener(“touch”,touchscreen);