Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Multitouch and event handling — Gideros Forum

Multitouch and event handling

DikkesnoekDikkesnoek Member
edited February 2014 in Step by step tutorials
Hi,

I've searched for a multitouch tutorial but I coulnd't find one.

I have two objects to control at the same time (two fingers).
There are two classes (object1 and object2) which have their
own mouse event handling routines. I don't know if that is a
good idea. Probably it's better to do this handling in the main
class. When I touch one object which I can control, it will
lose control when I touch the second object with my second
finger. Is there a tutorial how to handle multitouches?

Thanks in advance,

Marc

Comments

  • @Dikkesnoek first to do multi touch handling, you would need to implement Event.TOUCHES_BEGIN, Event.TOUCHES_MOVE, Event.TOUCHES_END events instead of mouse events

    And the second, that you would need to handle touch ids to know which object is dragged with which finger.

    So if for mouse dragging code would look like this:
    function Object:dragStart(e)
    	if self:hitTestPoint(e.x, e.y) then
    		self._isDragging = true
    		self._dragX = self:getX() - e.x
    		self._dragY = self:getY() - e.y
    	end
    end
     
    function Object:_dragMove(e)
    	if self._isDragging then
    		self:setX(e.x + self._dragX)
    		self:setY(e.y + self._dragY)
    	end
    end
     
    function Object:_dragEnd(e)
    	if self._isDragging then
    		self._isDragging = false
    	end
    end
    then with multi touch dragging it would look more like this:
    function Object:dragStart(e)
    	if self:hitTestPoint(e.touch.x, e.touch.y) then
    		--identifying drag by id
    		self._dragId = e.touch.id
    		self._dragX = self:getX() - e.touch.x
    		self._dragY = self:getY() - e.touch.y
    	end
    end
     
    function Object:_dragMove(e)
    	--identifying drag by id
    	if self._dragId == e.touch.id then
    		self:setX(e.touch.x + self._dragX)
    		self:setY(e.touch.y + self._dragY)
    	end
    end
     
    function Object:_dragEnd(e)
    	if self._dragId == e.touch.id then
    		self._dragId = nil
    	end
    end
  • I will implement and test this. Thanks a lot.

    Marc
Sign In or Register to comment.