Hey, I have two touch events in my coding for a came i’m making.
Here is the code:
function activateball(self, event)
self:applyForce( 0.3, 0 )
end
function moveright( event )
--print(“touch”)
if ( event.phase == “began” and event.x >
display.contentWidth*.5 ) then
ball.enterFrame = activateball
Runtime:addEventListener(“enterFrame”, ball)
end
if event.phase == “ended” then
Runtime:removeEventListener(“enterFrame”, ball)
end
end
Runtime:addEventListener(“touch”, moveright)
function activateball(self, event)
self:applyForce( -0.3, 0 )
end
function moveleft( event )
if ( event.phase == “began” and event.x <
display.contentWidth*.5 ) then
ball.enterFrame = activateball
Runtime:addEventListener(“enterFrame”, ball)
end
if event.phase == “ended” then
Runtime:removeEventListener(“enterFrame”, ball)
end
end
Runtime:addEventListener(“touch”, move left)
When I made the touch event “moveright” it worked fine, but when i added “moveleft” it made the object always move left no matter where I touch. Sorry if this is a dumb question, it’s my first time ever building a game so I really don’t know very much about it at all. Thanks.