Question regarding Touch Event

Hi guys, I just want to ask if it is possible to make a constraint on Touch? For example if it starts moving vertically it will not be able to move the touch horizontally? Thanks in Advance! :slight_smile:

Hi nealruiz70,

I don’t think so but you can ignore same touch event  e.g. add if statement to make sure that player moves finger on right from last position.

local rect = display.newRect( sceneGroup, display.contentCenterX, display.contentCenterY, 100, 100 ) local lastPositionX, lastPositionY function rect:touch( event ) if event.phase == 'began' then display.getCurrentStage():setFocus( self )   self.isFocus = true   lastPositionX, lastPositionY = event.xStart, event.yStart   self.markX = self.x   self.markY = self.y elseif self.isFocus then if event.phase == 'moved' then if event.x \> lastPositionX then self.x = event.x - event.xStart + self.markX   self.y = event.y - event.yStart + self.markY   lastPositionX, lastPositionY = event.x, event.y end elseif event.phase == 'ended'  or event.phase == 'cancelled' then display.getCurrentStage():setFocus( nil )   self.isFocus = false end    end end rect:addEventListener( 'touch' )

Have a nice day:)

ldurniat

Hi nealruiz70,

I don’t think so but you can ignore same touch event  e.g. add if statement to make sure that player moves finger on right from last position.

local rect = display.newRect( sceneGroup, display.contentCenterX, display.contentCenterY, 100, 100 ) local lastPositionX, lastPositionY function rect:touch( event ) if event.phase == 'began' then display.getCurrentStage():setFocus( self )   self.isFocus = true   lastPositionX, lastPositionY = event.xStart, event.yStart   self.markX = self.x   self.markY = self.y elseif self.isFocus then if event.phase == 'moved' then if event.x \> lastPositionX then self.x = event.x - event.xStart + self.markX   self.y = event.y - event.yStart + self.markY   lastPositionX, lastPositionY = event.x, event.y end elseif event.phase == 'ended'  or event.phase == 'cancelled' then display.getCurrentStage():setFocus( nil )   self.isFocus = false end    end end rect:addEventListener( 'touch' )

Have a nice day:)

ldurniat