Hello!
I've been working on my own game a few months from now, and I'm getting a really weird bug when it comes to multitouching the screen with just a little difference between fingers. I used the Touch Explorer to test the multitouching (after weeks of pain and code changing to see if i could fix it) and it turns out that the problem is not in my code, but in the multitouch hardware. See, the game is about fixing holes in a boat, and when there are 2 holes with about 20 - 30 pixels distance, i can't touch them both at the same time. Because the two touches merge into one just within the middle of the places i'm touching.
I really don't want to get to the idea that the hardware is going to make me change the gameplay. There must be a way to fix that; here's the code to touch events in case you can see some error or method that could help me fix that.
Thanks a lot in advance!
function hole:onTouchesBegin(event)
if not(self.beingHolded) then
local status = false
for i=1,#event.allTouches do
local touch = event.allTouches[i]
if self:hitTestPoint(touch.x, touch.y) then -- if any of the touches hit the object
status = true
event:stopPropagation()
break -- don't test other touches
end
end
if (status ~= self.beingHolded) then
self:statusChange(status) -- changes hole status.
end
end
end
function hole:onTouchesMove(event)
local status = false
for i=1,#event.allTouches do
local touch = event.allTouches[i]
if self:hitTestPoint(touch.x, touch.y) then
status = true
event:stopPropagation()
break
end
end
if (status ~= self.beingHolded) then
self:statusChange(status)
end
end
function hole:onTouchesEnd(event)
local status = true
for i=1,#event.allTouches do
local touch = event.allTouches[i]
if (self:hitTestPoint(touch.x, touch.y)) then
status = false
break
end
end
if (status ~= true) then
self:statusChange(status)
end
end
function hole:onTouchesCancel(event)
self:onTouchesEnd(event) -- same with touchesEnd
end
Also here's a video showing the problem. (and the awesome videogame
)
Comments
I don't know if it will change anything for you, probably not, but I've always found allTouches approach a bit too complicated and kind of ugly. Better prefer touch ID, as for example:
On a different subject: I'm really embarrassed for my awful english vocabulary (i mean for the being"holded" instead of beingheld) It's not my first language, but that's a terrible mistake! I must be violating some coding rules also along with the grammar! xD
Thank you for the advice I'll let you know if it helps on my problem.
The worst ever variable name is "data", because all variables hold data, and this name does not give you any pointer what this data is.
Want to know what is the second worst variable name?
data2
On the other hand, now I remember why I used the allTouches aproach. See with id method, If I tap outside a hole and then slide the same touch (touch move) to a hole, It won't change it's status so it won't recognice if it is being held O:-) It may seem nonsense to do that, but in gameplay, some of my lab rats (my friends who tested out the game) often slided from one hole to another afther this was sealed without taking the finger off the screen. That's why I did it that way. Anyways thank you for the answer (:.
By the way: What do you think of the game? Does it seem playable? Fun?
But that's easy, you simply use same method for touches move as you used for touches begin and thats all.
Anyways, thanks for the answers will let you know if I finish the game.