Touches are slowing down game

Member
Posts: 129
Joined: 2009.03
Post: #1
Hi,

I've got my game running quite nicely, but everytime I touch the screen (or move fingers on screen etc), it slows the game down. I'm testing on hardware, on an iPhone 2g device. I tried in release and in debug mode; and also 3.1.2 and 3.1.3.

Any suggestions, as to what could be causing this?

Thanks,
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #2
well, that would depend on what you have your touches (begin and move) functions doing.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #3
I seem to recall seeing that happening too. Even if I wasn't catching and using the touch events, I could quite measurably increase the CPU usage of my game by wiggling my finger around on the screen. IIRC it was something like 5-10%. Given that I wasn't doing anything with the events, I really just assumed that there was nothing more that I could do about it and moved on.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #4
Same conclusion as Skorche. All you can really do is tune your animation loop to ensure the event loop can "breathe". Blocking too much can cause events to queue up in bunches and make things even worse.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #5
Yeah, I'd really love to know why it blocks events like that. Super frustrating.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 129
Joined: 2009.03
Post: #6
Not sure what you mean by blocking events (bit of an iPhone newbie to be honest). I'm not really doing much though, on touchesBegan/Moved/Ended etc; just storing the touch data (which I use elsewhere, later).

I tried running my game at 30hz, which I can't notice any slow-down from the touches, but then of course, the animation is slightly 'blurred'. That's on am iPhone 2G though, which I think may be the lowest powered device there is?

I think the system processing the touches, may just push the amount of processing per frame, over the edge (and so it drops out of 60hz).

I may end up running at 30hz on a 2g and 60hz of 3g or 3gs. Guess it depends on the relative processing power of the devices.

There's also a good chance I don't know what I'm talking about; again, I'm very much an iPhone newbie. Smile
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #7
If you use too much CPU on the iPhone it sometimes stops sending touch events to your app. Then after storing them up for 10-20 seconds it sends them all in one big lump. I've noticed it in my games and in other peoples games. It seems that there isn't really anything you can do about it other than to add some extra wait times into your game loop so the CPU idles for a few milliseconds once in a while and lets whatever part of the OS that sends the touch events to catch up.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2010.03
Post: #8
You can't do much about it. Processing touches takes CPU time, and this happens somewhere on iPhone OS. You can't control that. There are ways to limit the time frame given for it, but you'd need to rewrite your game loop to run it manually (google more info about NSRunLoop). And it's not advised, because limiting time on it can ruin responsiveness. Just make sure it's not having a huge impact on gameplay experience and you'll be ok.
Quote this message in a reply
Member
Posts: 129
Joined: 2009.03
Post: #9
Just an updade.

Game is running smooth @ 60hz now, thanks to the CADisplayLink thingy. Before I was just using NSTimer, which I think it begins putting the backbuffer frame together at any point during the current display refresh (rather than at the start of the current display refresh). So the OS processing the touches was just pushing it over the edge. Or at least, that's my best guess / explaination.

Cheers, Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  touches offset? Jamie W 11 11,941 Aug 18, 2011 10:23 AM
Last Post: MattDiamond
  How to get number of active touches? Rasterman 8 7,786 Apr 21, 2010 03:56 PM
Last Post: longjumper
  not getting touches for top 20 pixels Rasterman 10 6,559 Apr 8, 2010 01:00 AM
Last Post: fattoh
  Touches Lagging & Skipping hippocoder 0 2,106 Mar 8, 2010 09:20 AM
Last Post: hippocoder
  Touches: Device vs Simulator vectorscope 4 4,643 Sep 22, 2009 03:25 PM
Last Post: Skorche