Hello,
First of all this is my second post in Corona Forums, my name is Luis Jose Regis (just tell me joe), i’m from Peru and ive been using Corona SDK for around 3 Weeks, i think Corona is a great tool for mobile development and im surely going to suscribe to launch my first game when it’s done.
I’m new to Corona SDK and also to Lua, i’ve been programming without problems so far, but i’ve found a little problem right now with the single touch event in my app.
The following code is supposed to be a character that moves to the right when a touch event is detected on the right of the character, otherwise if the touch event is detected to the left side of the character, he should move to the left.
function obj:touch(event)
print("touch event")
print("event("..event.phase)
if(event.phase == "ended")
then
self.touched = self.touched-1
print("Se acabo el movimiento")
if(self.touched == 0)
then
print("Touchs "..self.touched)
self.speedX = 0
end
end
if(event.phase == "began")
then
if(self.touched == 0 )
then
if(event.x\>self.x)
then
self.touched = self.touched+1
self.speedX = 300
end
if(event.x\<=self.x)
then
self.touched = self.touched+1
self.speedX = -300
end
print("Touchs "..self.touched)
end
end
Runtime:addEventListener("touch", obj)
Note: The var speedX is later used to make a move() method self.x = self.x + self.speedX
It works really well if you only use one finger to make the movement, but when it detects another touch event before the first one has been released it looks like it calls the “ended” event of the first touch, leaving your character without any move.
What i need is a way to prevent any other touch event after the first one has “ended”, tried to make it with a var “touched”, a counter of touchs, so the speed of the character will only be 0 when the “touched” var is 0, however it didn’t worked, you never have more than 1 touch and as i though it calls the “ended” of the first one when i touch the screen for second time.
Any Ideas? Thank you
Joe
[import]uid: 53575 topic_id: 11563 reply_id: 311563[/import]