touch delay on WP ( Lumia 930 )

  Hi everyone.

  I have been trying to port my game to WindowsPhone. I did some tricks: using BitmapText, native ads, v.v.v., now he’s running smoothly. The fps is sometimes drop down a little but it’s acceptable. I used acclerometer to control character and saw no delay with the acclerometer, the character moved as I tinted my device.

 But after testing some minutes Ingame, I come into a situation that the touches really delay. When pressing buttons, I only saw their response after some time ( 200 ms to 1 second ). Everything was still alright but not the touches :(. I swith to another scene, which removes the old scene to avoid leak. However, the touches are still delaying.

  My game can run perfectly on some devices: Nexus7, LG G2, Note3 v.v.v. I think that Lumia 930 has more power than them. I tested on another Lumia 1520 and see touchs delay too.

  Has anyone got this problem?

I highly doubt this is a touch latency issue.  In my experience, Windows Phone (aka: WP8) has proven to have the least touch latency compared to Android and iOS.  In fact, you tend to get more touch events on WP8 and it’s very common to receive multiple touch events per frame… which can lead to another issue.  If you’re updating display objects within your touch listener, then that’s the likely cause of your performance issue.  Since WP8 can provide multiple touch events per frame, you really should postpone your display object updates until the next “enterFrame” event.  This way you’ll avoid updating the same display objects multiple times, which is a huge waste because only the final update state of your display objects can be seen by the end-user at the end of the frame (ie: after the “enterFrame” event).

Note that Android can send multiple touch events per frame as well.  It’s pretty common actually.  But Android tends not to send as many touch events as WP8.  WP8 devices seem to have a much more sensitive screen or they’re just really good at providing low latency touch events efficiently.

As a quick test to prove my point, comment out what you are doing within your touch listener and print() the begin and end phases of the touch event.  Or leave it completely commented out and test with a tap event, which really use WP8’s internal touch events.

  Hi Joshua, nice to meet you again :slight_smile:

  My game uses accelerometor to control player. I tint my device to make charater move left or right with two buttons to make him jump or drop down. So touchs are only used for working buttons. That’s all. I don’t call update obj or st else when touching buttons. 

  It only happens after a few minutes playing. It ran smoothly at start. Then, I feel the delay. When pressing button, it didn’t change state immediately. After some time of delay, the button changed state and the character dropped down. At this time, all touchs delay. I pressed pause button and sometimes it delayed 1 second to pause the game. As I said, I went to another scene, removed old scene, but come here the same problem.

 I use widget library to create buttons. I will try print debug for touching count and time to see what happends here

Perhaps this performance issue is only happening while running your app via the Visual Studio debugger?

I say this because printing/logging to the Visual Studio debugger can cause performance issues too.

After installing your app to your WP8 device via Visual Studio, stop the debugger, then go to the app selection list and launch your app normally.  See if it performs any better.

Also, we used to have performance issues with creating/updating widget buttons that had no text in them, but that was remedied 2 releases ago.

Yeap, I thought about that and tested my app without Visual Studio debugger, but buttons still delayed after a few minutes of playing.

I would try to build and test some simple apps and games to check if it was caused by the WP problems or my game’s performance issues. I’m not sure it was due to performance issues, because the game still responds to accelerometer immediately, and I didn’t feel fps drop too much. Only touches delayed T_T

My Game uses physics, so I will try to check on some other apps without it. I will be back with more information.

I just ran the newest daily build of CoronaCards for WP8 and touch events worked pretty smoothly for me.  I ran it with the following “main.lua” file…

system.activate( "multitouch" ) local touchCircles = {} local function onTouch(event) if (event.phase == "began") then local circle = display.newCircle(event.x, event.y, display.contentWidth \* 0.2) touchCircles[event.id] = circle elseif (event.phase == "moved") then local circle = touchCircles[event.id] if circle then circle.x = event.x circle.y = event.y end elseif (event.phase == "ended") or (event.phase == "canceled") then local circle = touchCircles[event.id] if circle then touchCircles[event.id] = nil circle:removeSelf() end end end Runtime:addEventListener("touch", onTouch) display.newText("Touch Me", display.contentCenterX, display.contentCenterY, nil)

And the following “config.lua” file (don’t forget to set it to 60 FPS)…

application = { content = { fps = 60, width = 320, height = 480, scale = "letterbox", }, }

Can you try the above on you device too please?  If it runs smoothly on your device as well, then I suspect something else is the cause of the performance issue.

 Thank for your advice. I will try more and back with some information

 Hi Joshua, I’m done with some tests. 

 You codes ran smoothly on devices without any delaying touch. I tried another widget sample from Corona SDK and it had nice respone, too. Maybe you’re right, the problem’s due to performance issue.

 But I didn’t feel any fps drop, my game still run smoothly. Animation, player’s move, accelerometor event etc were still working perfectly. But only touchs delayed !

 Do you wanna try to play my game and tell me what happens with it? I could send you a demo version of windows phone. Please send me your email address if possible.

 Btw, here is the Android version:

https://play.google.com/store/apps/details?id=com.rubycell.game.bunnyjump.wow

 It can run okay without any problem on devices like: Galaxy Note 3, Nexus 7, Galaxy S3 etc. No touch delays at all.

You can send us your project by clicking the “Report a Bug” link at the top of this webpage.  But we’ll probably won’t have time to look into it this week since we have a major holiday (Thanksgiving) this week.  So, let’s see if we can narrow it down.

>> But I didn’t feel any fps drop, my game still run smoothly.

Hmm… that’s interesting.  I’ve never seen that before.  Just to confirm, would you mind adding the following code to your “main.lua” file please?  This will print the average FPS once a second to your Visual Studio “Output” panel.  Double check to see if dragging your finger onscreen is causing any large dips in the framerate.  If it’s not, then yeah, it sounds like touch events are being delivered late on the Microsoft Silverlight side.

local lastEnterFrameTime = nil local durationCollectionSize = 60 local durationCollectionIndex = 1 local durationCollection = {} for index = 1, durationCollectionSize do durationCollection[index] = 0 end local function onEnterFrame(event) local currentTime = system.getTimer() -- If this is the first frame, then fetch the current time and exit out. if (lastEnterFrameTime == nil) then lastEnterFrameTime = currentTime return end durationCollection[durationCollectionIndex] = currentTime - lastEnterFrameTime lastEnterFrameTime = currentTime if (durationCollectionIndex \< durationCollectionSize) then durationCollectionIndex = durationCollectionIndex + 1 return end local averageDuration = 0 for index = 1, durationCollectionSize do averageDuration = averageDuration + durationCollection[index] end averageDuration = averageDuration / durationCollectionSize local averageFps = 1000 / averageDuration print("Average FPS = " .. tostring(averageFps) .. ", Average Duration = " .. tostring(averageDuration)) durationCollectionIndex = 1 end Runtime:addEventListener("enterFrame", onEnterFrame)

If the touch delay is coming from the .NET side for whatever reason, some feature that your app is using must be causing it.  Are you using any 3rd party libraries such as AdMob?  I remember AdMob would cause some random lag, but it was to the main UI thread as a whole which affected the framerate too.  You might want to try commenting out features like that to see if that’s where the issue is coming from.

 Regarding the 3rd party, I’ve just started to port my Game, so I’ve not used any 3rd party yet. The only non-ingame module is Gg Analytics with http request.
 I’ve done with your test. The average FPS is between 55->60. And buttons delays about 100 -> 500 ms. This only happens after a few minutes of playing. But my game run smooth so I don’t think about leak :frowning:

Does your app do anything with the touch event’s timestamp?  (ie: The “event.time” property?)

I ask because I’ve noticed that the touch event’s timestamp don’t match what we’ve documented.  They’re not in milliseconds since app startup.  That shouldn’t cause a delay though.  But it might screw up a calculation somewhere.

And you said this is only an issue with widget buttons?  It’s not an issue in your own code?  It takes about 100-500ms for button tap to register?

 I did nothing with touch event’s timestamp.

 My game ran on android perfectly so I think it is not caused by logic code. Guess that as you said, st happened in Microsoft Silverlight side.

 Sorry for my misunderstanding, let me make it clearer. I tried my own custom buttons, but here comes the same result. I pressed on a button, and it changed to ‘pressedState’ after ‘delayTime’. I ‘released’ the button, and it was back to ‘defaultState’ after ‘delayTime’. Touches delayed in all of my game. The buttons include widget button or my custom buttons.

I don’t think this is a touch event issues since we’ve proved that my code up above works fine on your devices.

I don’t think this is a performance issue either since your app I running at 60 FPS just fine.

So, I’m thinking this must be timer related.  That would explain why there is a delay but no impact on framerate.  Although our widget button code doesn’t use any timers that I know of.

In daily build #2755, we made changes to the Win32 and WP8 versions of Corona to provide much more accurate timers and timestamping.  Are you using daily build #2755 or newer?  If so, then trying using daily build #2754 and see if that gets rid of the delay.

   https://developer.coronalabs.com/release/2015/2754/

You’ll need to uninstall the CoronaCards extension from Visual Studio in order to go back a version.  We provide instructions on how to uninstall here…

   https://docs.coronalabs.com/daily/coronacards/wp8/uninstall.html

  Recently I’ve used CoronaCard build #2775.

  I don’t know how the enginer works, so I can’t guess what the problem is. But for my own custom buttons, i only use a simple code which looks like:

button:addEventListener("touch",function(event) if event.phase == "began" then button:setDisplayState("over") else --other logic end end)

 Hi Joshua.

 Did you comeback from Thanksgiving :slight_smile:

At this point, I’m  not sure how to help you further.  We’ve proved that the touch events are not actually delayed.  And that you’re not running into a performance issue.  So, it must be whatever the touch event is triggering in Lua.  Try adding your button to the multitouch code I posted up above.  See if you can reproduce it with a much simpler app.  That’ll make it easier to isolate.

 Okay. My project is too big to be used in an issue report.

 I will try to reproduce it with a much simpler app.

I highly doubt this is a touch latency issue.  In my experience, Windows Phone (aka: WP8) has proven to have the least touch latency compared to Android and iOS.  In fact, you tend to get more touch events on WP8 and it’s very common to receive multiple touch events per frame… which can lead to another issue.  If you’re updating display objects within your touch listener, then that’s the likely cause of your performance issue.  Since WP8 can provide multiple touch events per frame, you really should postpone your display object updates until the next “enterFrame” event.  This way you’ll avoid updating the same display objects multiple times, which is a huge waste because only the final update state of your display objects can be seen by the end-user at the end of the frame (ie: after the “enterFrame” event).

Note that Android can send multiple touch events per frame as well.  It’s pretty common actually.  But Android tends not to send as many touch events as WP8.  WP8 devices seem to have a much more sensitive screen or they’re just really good at providing low latency touch events efficiently.

As a quick test to prove my point, comment out what you are doing within your touch listener and print() the begin and end phases of the touch event.  Or leave it completely commented out and test with a tap event, which really use WP8’s internal touch events.

  Hi Joshua, nice to meet you again :slight_smile:

  My game uses accelerometor to control player. I tint my device to make charater move left or right with two buttons to make him jump or drop down. So touchs are only used for working buttons. That’s all. I don’t call update obj or st else when touching buttons. 

  It only happens after a few minutes playing. It ran smoothly at start. Then, I feel the delay. When pressing button, it didn’t change state immediately. After some time of delay, the button changed state and the character dropped down. At this time, all touchs delay. I pressed pause button and sometimes it delayed 1 second to pause the game. As I said, I went to another scene, removed old scene, but come here the same problem.

 I use widget library to create buttons. I will try print debug for touching count and time to see what happends here

Perhaps this performance issue is only happening while running your app via the Visual Studio debugger?

I say this because printing/logging to the Visual Studio debugger can cause performance issues too.

After installing your app to your WP8 device via Visual Studio, stop the debugger, then go to the app selection list and launch your app normally.  See if it performs any better.

Also, we used to have performance issues with creating/updating widget buttons that had no text in them, but that was remedied 2 releases ago.