Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to dispatch TOUCHES_END(again and again) until user touches the screen — Gideros Forum

How to dispatch TOUCHES_END(again and again) until user touches the screen

simransimran Member
edited June 2014 in General questions
I am dispatching events when user touches the screen and removes the touch. But, the event is dispatched only once, I want the Touches_End event to be dispatched continuously until user touches the screen, how can I do that?Please?

I tried updating it in Event.Enters_Frame function and added listener in Event.TOUCH_ENDS function, but it doesn't work.


function Play: whenEntersFrame()
speed = 20
x,y = mc1:getPosition()
repeat
y = y+ speed
mc1:setPosition(x, y)
until self.touchStarted ~= true
end

Comments

  • ar2rsawseenar2rsawseen Maintainer
    @simran well touches end is a native event and is only dispatched on real gesture
    you can try to emulate it, but it is not recommended
    basically if you want to do something while user touches the screen, you better do it inside the enter frame ;)
  • simransimran Member
    edited June 2014
    @ar2rsawseen: But, that's what exactly I tried to do in above piece of code(updating position in EnterFrame) and it did not work :(
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    so what exactly is not working, are you setting self.touchStarted property on touch events?
    and
    1) And why are you using until loop? it means it will always be called at least once
    2) why would you use loop at all? enter frame in itself is a loop, and is called on every frame,
    simply this should be enough ;)
    local speed = 20
    function Play: whenEntersFrame()
        if self.touchStarted then
            mc1:setY(mc1:getY()+ speed)
        end
    end
  • simransimran Member
    @ar2rsawseen: Ok, you have self.touchStarted in if condition. but it should be if not self.touchStarted according to my script(self.touchStarted = false when touch ends), If I do this:

    if self.touchStarted then
    mc1:setY(mc1:getY()+ speed)
    end

    The player just keeps going down and I want that when self.touchStarted is not true.

    I did this:

    if not self.touchStarted then
    mc1:setY(mc1:getY()+ speed)
    end

    and player doesn't at all appears on the screen. Why that might be happening?
  • simransimran Member
    Yes, setting touch.Started in touchEvents only.

    self.touchStarted = true when Touch begins and self.touchStarted = false when touch ends
  • simransimran Member
    Done , Done, Done :)
Sign In or Register to comment.