Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Drag example slow delay with Gideros Android Player — Gideros Forum

Drag example slow delay with Gideros Android Player

stephenttstephentt Member
edited March 2013 in General questions
Hello all,

I was wondering if someone could help me with some drag and touch code I'm trying to figure out.
I've just started to learn Gideros and I've written some code that basically drags a ball.png using touch events.

Everything is working, I'm able to drag the ball.png, but I find that there's a slight delay from when I drag the ball.png to where I move my finger when I run the code on the Android Gideros player.

I think I need to update the ball.png xy location in the Enterframe event, but I'm not sure how to do this;

Could someone please take a look at my code and let me know how I update the code so the ball.png is update to match the exact location where I touch drag the screen on my android device?


Here's my code:

--[[

Drag the shapes around with your mouse or fingers

This code is MIT licensed, see http://www.opensource.org/licenses/mit-license.php
(C) 2010 - 2011 Gideros Mobile

]]
local ball = Bitmap.new(Texture.new("ball.png"))

local function onTouchesBegin(self, event)
if self:hitTestPoint(event.touch.x, event.touch.y) then
self.isFocus = true

self.x0 = event.touch.x
self.y0 = event.touch.y

event:stopPropagation()
end
end

local function onTouchesMove(self, event)
if self.isFocus then

local dx = event.touch.x - self.x0
local dy = event.touch.y - self.y0

self:setX(self:getX() + dx)
self:setY(self:getY() + dy)

self.x0 = event.touch.x
self.y0 = event.touch.y


event:stopPropagation()
end
end

local function onTouchesEnd(self, event)
if self.isFocus then
self.isFocus = false
event:stopPropagation()
end
end

local function onTouchesCancel(event)

end

-- before entering each frame, we update the position of the ball
function onEnterFrame(event)


end

-- create a ball bitmap object (Bitmap class inherits from Sprite class)
ball:addEventListener(Event.TOUCHES_BEGIN, onTouchesBegin, ball)
ball:addEventListener(Event.TOUCHES_MOVE, onTouchesMove, ball)
ball:addEventListener(Event.TOUCHES_END, onTouchesEnd, ball)



stage:addChild(ball)

local info = TextField.new(nil, "drag the shapes around with your mouse or fingers")
info:setPosition(23, 50)
stage:addChild(info)
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)


Thanks,

Stephen T.

Likes: stephentt

Dislikes: amin13a

+1 -1 (+1 / -1 )Share on Facebook

Comments

  • are you using latest gideros version ?????

    if not go with that there are some improvements in touch

    if yes then it is normal because touch event are firing almost 100 times a second but screen refresh rate is usually locked at 60 or even 30 so you will always see your sprite is little bit behind your finger while moving.

    :)
  • at the other hand you can move your finger from pixel(0,0) to pixel (1280,0) in just one second and according to you you had touched each and every pixel in your way but still device can update position of your ball just 60 or 30 times in one second see what i mean.

    :)
  • Hey hgvyas123,

    Well if the touch updates a 100 times then maybe I can set the onenterframe to match?

    Stephen
  • Nup

    Thats the main problem over here onenterframe event can fire at max 60 times a second so whatever you do you will be slightly behind the touch position depends upon how fast your finger is moving

    :)
  • Wow, that's not so good. With html5 a similar drag example is updated in real time. Is it possible to increase the onenterframe to something high than 60 fps?
  • ar2rsawseenar2rsawseen Maintainer
    I really don't think that it should be a problem, since move event gets dispatched, you calculate the difference between position and if you move your finger very fast, move even won't be dispatched as fast and ball should jump with larger chunks but pretty similar to the speed of finger.
    @stephentt I'd actually used same method as you and did not had any noticeable problems.
    So again do you use latest Gideros version?
    Is there anything else inside on touch event?
    Is there anything else in your app?
    What phone are you testing it on?
    Does it happens only on Gideros player?
  • atilimatilim Maintainer
    edited March 2013
    There is always a delay with real Android and iOS devices. For example, look at the video at the end of this article: http://gigaom.com/2012/01/19/video-android-touch-lag-and-a-possible-solution/ Here they claim that they solve the touch lag problem but I can easily see the lag :)

    Likes: hgvyas123

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.