Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Is there any method to get a more precise touch location for multitouching? — Gideros Forum

Is there any method to get a more precise touch location for multitouching?

Ozkar619Ozkar619 Member
edited September 2012 in Bugs and issues
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 :3)

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Hello,
    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:
    function hole:onTouchesBegin(event)
    	--check if is not laready being held and check testpoint
    	if not self.beingHolded and self:hitTestPoint(event.touch.x, event.touch.y) then 
    		--if we are touching this object, store event's id
    		self.beingHolded = event.touch.id
    		event:stopPropagation()
    	end
    end
     
    function hole:onTouchesMove(event)
    	--now check if this object has provided event ID
    	if self.beingHolded == event.touch.id then
    		--do what you need on move
    	end
    end
     
    function hole:onTouchesEnd(event)
    	--now check if this object has provided event ID
    	if self.beingHolded == event.touch.id then
    		--do what you need on end
    		self.beingHolded = nil
    	end
    end
     
    function hole:onTouchesCancel(event)
    	self:onTouchesEnd(event) -- same with touchesEnd
    end
  • Ozkar619Ozkar619 Member
    edited September 2012
    Hello,
    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:
    function hole:onTouchesBegin(event)
    	--check if is not laready being held and check testpoint
    	if not self.beingHolded and self:hitTestPoint(event.touch.x, event.touch.y) then 
    		--if we are touching this object, store event's id
    		self.beingHolded = event.touch.id
    		event:stopPropagation()
    	end
    end
     
    function hole:onTouchesMove(event)
    	--now check if this object has provided event ID
    	if self.beingHolded == event.touch.id then
    		--do what you need on move
    	end
    end
     
    function hole:onTouchesEnd(event)
    	--now check if this object has provided event ID
    	if self.beingHolded == event.touch.id then
    		--do what you need on end
    		self.beingHolded = nil
    	end
    end
     
    function hole:onTouchesCancel(event)
    	self:onTouchesEnd(event) -- same with touchesEnd
    end
    On one point: Im gonna try it, it seems much cleaner and easier to understand.

    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.
  • @Ozkar619 I haven't heard any grammar restriction on code, you can name your variables as you want while it represents the value you are holding in.
    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

    :)
  • Ozkar619Ozkar619 Member
    edited September 2012
    hahahahahaha xD also "variable" would be a bad variable name :P
    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. :3 Anyways thank you for the answer (:.
    By the way: What do you think of the game? Does it seem playable? Fun? :D
  • @Ozkar619
    But that's easy, you simply use same method for touches move as you used for touches begin and thats all.
  • @ar2rsawseen You sir, are a genius.
  • ar2rsawseenar2rsawseen Maintainer
    edited September 2012
    But main question is, does it solve your initial problem or not? :)
  • It doesn't :/ I think it's a hardware issue. Damn, I'm gonna have to get creative to fix this one. Maybe change the gameplay or something.
    Anyways, thanks for the answers :) will let you know if I finish the game.
Sign In or Register to comment.