Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
IOS Touch latency problem. — Gideros Forum

IOS Touch latency problem.

mehmetuysalmehmetuysal Member
edited February 2013 in Bugs and issues
Hi,

I am developing my new game with Gideros after 3 games in Corona. I gave up Corona because of android performance issues.

I have tested game on android tablets and some android phones, performance is really fine. But, when I started to test on iPhone, there is observable touch latency problem. Android can detect touch perfectly, but ios detects in half second. I have used EVENT.MOUSE_DOWN, EVENT.MOUSE_UP events. Is there any difference between "touch" and "mouse" events ? Please help me, I have finished everything with gideros. I like that very much. So I do not want to move to other development platforms and rewrite code.

Comments

  • @mehmetuysal do you use latest Gideros version?
    I don't remember since which version, but there was an optimization for mouse/touch events.

    Earlier mouse events were for desktop and touch events for mobiles, now you can select in project properties to dispatch events on both. So there should not be any huge difference.

    One thing to try you can put event:stopPropagation() in all you touch/mouse events to stop events and prevent them form dispatching on other elements.
  • I am using v2012.09.9. I think it is latest version.

    I thought, converting mouse events to touch event can cause performance issue so I changed mouse events to touch. But both has same problem.Also I'm using event:stopProgation().

    Is there any other way to optimize touch events performace ?
  • @mehmetuysal not that I know of.

    well the problem is, that I don't know any other who would experience performance issues with touch events on IOS platform.

    Is it through the Gideros player or exported app? Maybe you have older Gideros player?
    Maybe it's some specifics you do inside touches, what exactly you do in them?
  • I am building game like diamond dash. 8x7 touchable boxes on screen.
    I have tested in gideros player, android tablet and an old android phone with player and built apk. All has perfect performance.

    With gideros player(on device) and exported built has poor touch performance on IOS device. I have tested on Xcode native ios simulator now. That works well because of computers CPU.

    If issue causes because of specifics inside touches, same problems should occur on android devices too ?
     
    function Engine:onMouseDown(event)
     
    	if(game_paused==false) then
    			if(self:hitTestPoint(event.x,event.y) and idle == false) then
    				self.isFocus = true
    				...
    				...
    				..
    				...
                                    event:stopPropagation()
    			end
            else
                  event:stopPropagation()
    	end
    end
  • In gideros
    function Engine:onMouseDown(event)
        print('test')
    end
    writes 'test' more than 50-60 times. So I guess that checks all objects on the screen, until find the correct one

    in corona
    function Engine:onMouseDown(event)
        print('test')
    end
    writes 'test' 2-3 times.

    I think this can cause the problem. Does gideros needs some core code optimization ? or am I doing something wrong. Is there anything to check in my code ?
  • bowerandybowerandy Guru
    edited February 2013
    @mehmetuysal, mouse events are sent to all objects on the stage that register for them. They are not specific to whether the event actually occurs inside the object bounds or not.

    I have not experienced any latency issue with Gideros and iOS. Are you using a particularly old (i.e. slow) device? There should be no problem searching 56 objects for a touch location - this should occur almost instantly.

    Are you sure there are only 56 objects on the stage? Previously people who have experienced performance issues have inadvertently been adding far more objects than they think they have.

    Also, your code looks slightly odd to me. Is Engine a class of which there is a single global instance or are there 56 of them. Perhaps you are registering all 56 objects with your single engine class? If this is the case then your onMouseDown() function is hit testing against the engine and not the target of the touch.

    best regards
  • @mehmetuysal no this is how the things are supposed to be in Gideros. :)

    Basically touch/mouse event is called on all objects that registered to it. Then inside it you can check using hitTestPoint was this touch meant for specific element.
    This gives you a flexability of, for example, increasing touch area of small images/buttons, or checking that specific image on top or bottom received the event.

    but once you are inside if self:hitTestPoint ...
    then it means you have found what you needed and you can call event:stopPropagation() so it will not be dispatched further.

    I hope @atilim could shed more light on the issue, in the meantime, it might be useful to prepare a small example of a slowdown that you could share with others to test. ;)
  • @bowerandy
    I have box and engine classes. I am creating 56 boxes from box class and add to engine sprite class. I am adding touch/mouse eventlistener for all boxes. I didnt create touch events in box class, because box needs interaction with other boxes. I am counting max 30-35 touch calls until hittest returns true.

    May be my code needs optimization. But as I said before, I just want that should work like on my andorid device( 2 years old HTC Desire). I am testing on IPhone4. I will test on blank project only for touch performance.

    Thank you very much for your answers
  • @mehmetuysal, okay. In that case maybe you should be hit testing against event.target rather than self in your above code? It seems to me that in the above, self is always the engine. The event.target field should have the box object that received the event. Does this make any difference?

    best regards
  • atilimatilim Maintainer
    I also think @bowerandy is correct. hitTestPoint function is called on whole Engine object 56 times.
  • Yes,I think that checks whole stage child sprites. So what am I supposed to do ?

    @bowerandy, I change to event.target. Nothing changed.

    Android is ok, but ios still has noticiable latency. I will test with blank project tomorrow. I hope I will solve the problem.
  • atilimatilim Maintainer
    Also playing an .mp3 file with each touch can cause such latency. If you're doing so, convert your .mp3 file to .wav.
  • bowerandybowerandy Guru
    edited February 2013
    @mehmetuysal, try the following code in a main.lua and, once you've validated that it works okay, adapt it for your app:
    local BOX_COUNT=100
     
    MyBox = Core.class(Sprite)
     
    local engine
     
    function MyBox:init(size, id)
    	self.id=id
     
    	local shape=Shape.new()
    	shape:beginPath()
    	shape:setFillStyle(Shape.SOLID, 0xff0000)
    	shape:moveTo(0, 0)
    	shape:lineTo(size, 0)
    	shape:lineTo(size, size)
    	shape:lineTo(0, size)
    	shape:closePath()
    	shape:endPath()
    	self:addChild(shape)
     
    	self:addEventListener(Event.TOUCHES_BEGIN, engine.onTouchBegin, engine)
    	self:addEventListener(Event.TOUCHES_END, engine.onTouchEnd, engine)
    end
     
    Engine=Core.class()
     
    function Engine:init()
    	engine=self
    	for i=1, BOX_COUNT do
    		local x=math.random(application:getContentWidth())
    		local y=math.random(application:getContentHeight())
    		local box=MyBox.new(30, i)
    		stage:addChild(box)
    		box:setPosition(x, y)
    	end
    end
     
    function Engine:onTouchBegin(event)
    	local target=event:getTarget()
    	if target:hitTestPoint(event.touch.x, event.touch.y) and not(target.touchId) then
    		-- Remember the touch id as a focus indicator. 
    		-- This allows you to track different fingers if you need to.
    		target.touchId=event.touch.id
    		print("pressed box", target.id)
    		target:setScale(0.5)
    		event:stopPropagation()
    	end
    end
     
    function Engine:onTouchEnd(event)
    	local target=event:getTarget()
    	if target.touchId==event.touch.id then
    		print("released box", target.id)
    		target:setScale(1)
    		target.touchId=nil
    		event:stopPropagation()
    	end
    end
     
    Engine.new()
    I tried increasing the BOX_COUNT to 10,000 and, although the creation process takes 2 seconds, the touch latency is imperceptible (fine work @atilim). I am using an iPad 3 though, so slower devices may not perform quite so well.

    best regards

    Likes: atilim

    +1 -1 (+1 / -0 )Share on Facebook
  • @bowerandy this code works exactly like mine. This has no latency. So I rechecked everything at my code. I have 2 sounds playing after a box touched. After I've removed sounds, latency has gone. Than I have increase BOX_COUNT to 300 and added my 2 sounds to @bowerandy test code, then problem come back.

    As a result, sounds caused my problem. I am using mp3. What am I supposed to do for better sound performance? I attached test code with sounds.

    thank you all, for your helps
    zip
    zip
    performance.zip
    13K
  • I think is better to use wave format for sound effects; if I remember correctly mp3 is better for background music (because mp3 is more CPU intensive than wav).

    Hope it helps.
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • bowerandybowerandy Guru
    Accepted Answer
    @mehmetuysal, see @atilim 's (and @GregBUG 's) comment above. MP3 sounds will cause such latency. Convert them to WAV and you should be okay.

    best regards
  • mp3 was the problem. I convert mp3s to wav then latency has gone. You saved my life. Thank you all.
Sign In or Register to comment.