Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Unexpected jump when dragging an object with a touch event
Started by R2robot Jul 24 2018 01:29 PM

- - - - -
5 replies to this topic
touch event touch drag dragging
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

R2robot

[GLOBAL: userInfoPane.html]
R2robot
  • Observer

  • 13 posts
  • Corona SDK

--- Console Log ----
Jul 24 04:08:15.803 [Device] eventX: 156.5 eventY: 157
Jul 24 04:08:15.822 [Device] eventX: 145.5 eventY: 148.5
Jul 24 04:08:15.839 [Device] eventX: 133 eventY: 140
Jul 24 04:08:15.855 [Device] eventX: 122 eventY: 132.5
Jul 24 04:08:15.889 [Device] eventX: 443 eventY: 270.5  <--- unexpected jump across the screen
--------------------
 
--- Console Log ---
Jul 24 04:26:50.692 [Device] eventX: 85 eventY: 85
Jul 24 04:26:50.727 [Device] eventX: 96 eventY: 94
Jul 24 04:26:50.759 [Device] eventX: 104.5 eventY: 103
Jul 24 04:26:50.793 [Device] eventX: 112 eventY: 110
Jul 24 04:26:51.064 [Device] eventX: 442.5 eventY: 267 < ---
--------------------
 
 
Thought it was a bug in my game, but I broke it down to the bare essentials in a new standalone project and still get this wonky jump when testing on my phone ( iPhone 5s )
 
So now I'm not sure if it's a bug in Corona, or if my phone is getting wonky.  I don't have a secondary device to test with and I haven't noticed the issue in the simulator.  =/
 
 
 
Edit:  Forgot the code snippet I'm using.    I'm able to reproduce it with this..  I usually start to drag to the lower right hand corner when it happens.   It doesn't happen every single time.. just randomly after repeating it several times.
local box = display.newRect( 10, 10, 50, 50 )
box.anchorX = 0
box.anchorY = 0

local function touchHandler( event )

    if( event.phase == "began") then

        display:getCurrentStage():setFocus( event.target )
        event.target.isFocus = true

        event.target.touchOffsetX = event.x - event.target.x
        event.target.touchOffsetY = event.y - event.target.y


    elseif( event.target.isFocus ) then

        if( event.phase == "moved" ) then

            print( "eventX: " .. event.x .. " eventY: " .. event.y )

            event.target.x = event.x - event.target.touchOffsetX
            event.target.y = event.y - event.target.touchOffsetY


        elseif( event.phase == "ended" or event.phase == "cancelled" ) then

            display.getCurrentStage():setFocus( nil )
            event.target.isFocus = nil

        end

    end

    return true

end

box:addEventListener( "touch", touchHandler )
Edit 2: I don't think I was clear that it's the event position that i'm receiving from corona that makes the jump, not the calculation i'm doing..(well, I mean, that jumps too, but only because what I am getting from the touch event) Hence why I think it's a bug or my phone is b0rked.

Also, video example here:


[TOPIC: post.html]
#2

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,069 posts
  • Corona SDK

You haven't posted any code. How are we to know what you are trying to do?



[TOPIC: post.html]
#3

R2robot

[GLOBAL: userInfoPane.html]
R2robot
  • Observer

  • 13 posts
  • Corona SDK

You haven't posted any code. How are we to know what you are trying to do?

 

whoops!  I got distracted when writing the original because I saw that my posts need to be approved by a moderator and hit "post" to see what would happen.. lol     Updated with code snippet



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,516 posts
  • Corona SDK

That offset calculation is probably the issue.

 

I'd do this:

local function touch( self, event )
   local phase = event.phase
   local id    = event.id
   if( phase == "began" ) then
      self.isFocus = true
      display.currentStage:setFocus( self, id )
      self.x0 = self.x
      self.y0 = self.y
   elseif( self.isFocus ) then
      local dx = event.x - event.xStart
      local dy = event.y - event.yStart
      self.x = self.x0 + dx
      self.y = self.y0 + dy  
      if( event.phase == "ended" ) then
         self.isFocus = true
         display.currentStage:setFocus( self, nil )
      end
   end
   return true
end


local box = display.newRect( 10, 10, 50, 50 )
box.anchorX = 0
box.anchorY = 0

box.touch = touch
box:addEventListener( "touch" )


[TOPIC: post.html]
#5

R2robot

[GLOBAL: userInfoPane.html]
R2robot
  • Observer

  • 13 posts
  • Corona SDK

 

That offset calculation is probably the issue.

 

I'd do this:

 

Thank you, I'll try that.

 

But what I was originally confused by is the event location.   I was printing out the event location and not my calculated position.    I shouldn't be able to affect what location I receive from corona a corona touch event except by actually touching the screen, right?

 

The event reported jumps all the way across the screen in ~0.050s.    My name is 'robot', but I'm not THAT fast!  :D

 

Edit:

 

Get the same jump with your bit.  Something is happening with the event.

 

Jul 25 10:51:45.230 [Device] event x: 120 event.y 109
Jul 25 10:51:45.244 [Device] event x: 114 event.y 104
Jul 25 10:51:45.269 [Device] event x: 101 event.y 98.5
Jul 25 10:51:45.303 [Device] event x: 439 event.y 265
Jul 25 10:51:45.303 [Device] event x: 441 event.y 267



[TOPIC: post.html]
#6

R2robot

[GLOBAL: userInfoPane.html]
R2robot
  • Observer

  • 13 posts
  • Corona SDK

Welp, I implemented the same little test code in Cocos2d and got the same jump. I guess my phone is b0rked! RIP Thanks for the help/suggestions.


[topic_controls]
[/topic_controls]