views:

99

answers:

3

I had an idea for an app that would require me to implement these little sprites that would require basic physics features like gravity, acceleration, etc... so naturally I looked into a game loop for the iPhone, there were plenty of threads on this, but what I am trying to understand is that I want to be able to create these sprites and have them behave naturally using a game loop, but still have full "standard" iPhone interaction, i.e. touches, pinching, swiping, core animation, core data, etc...

Is this just as simple as implementing a game loop on a background thread and updating sprites on that thread then doing the standard operations on the main UI thread (except of course for obvious background tasks)?

I would like some general overview of this type of thing if thats possible.

+1  A: 

In Xcode try creating a iPhone OpenGL ES project. Just build and run with the default code. You should see a box moving up and down. This simple example should give you an insight into animating objects and how the OS version of the device matters. The OpenGL view is based off a normal view that you can attach gesture watchers to.

No one in particular
opengl is not an area that I am familiar with, so I would like to avoid it.. although I should probably get into it sometime, I just dont really have the time for the learning curve
Mark
I know that pain. But it does show how for iOS 3.2 you can use CADisplayLink but need to revert to NSTimer for anything before 3.2 for creating an animation loop. I've not tried but you might be able to use this on a normal UIView with no OpenGL.
No one in particular
Interesting, I actually think that 3.2 (iPad) might be the way to go here, CADisplayLink looks like a very similar technique to the WPF way of achieving the looping method (of which I am very familiar with). Theoretically, you could hook into standard UIViews
Mark
A: 

Check out one of the available game physics engines. Cocos2D is a good place to start: http://www.cocos2d-iphone.org/ -- free and lots of resouRces to get started with.

TomH
I have looked into this framework a little, you think this can be used for this type of thing? The documentation is not brilliant (wiki's just dont do it for me...), and from what I can tell its mainly focused around games, but I suppose it should do the trick...
Mark
+1  A: 

I wanted the same thing, but the iPhone SDK is all about async and callbacks and it's better to roll with the framework rather than fight it. If Cocos2d does not satisfy you, you could look into hooking into NSRunLoop.

With regards to CADisplayLink: I noticed a drop in performance (decreased triangle throughput) when using CADisplayLink with OpenGL ES (which you have stated you are not using so I will not elaborate further).

MrAnonymous
so did you end up using Cocos2d?
Mark
Better answer (can't edit old one): No. I'm not making a game but I have used Cocos-2d for reference. My app is not a "game" with a bunch of objects--it's a high throughput drawing app. Cocos-2d is geared toward manipulating objects and re-rendering them. As for threads: iOS SDK pushes hard for using async tasks with callbacks and I worked with it. The only time I would use a thread for CPU task is if I wanted to have a more responsive main run loop (so my app doesn't get killed by the watchdog). Also, current iOS devices only have a single-threaded single core ARM.
MrAnonymous
I see, so you simply used it for reference code? Interesting, I was thinking of doing that too, perhaps I should open up the source and take a look. At the end of the day I am only interested in getting animated sprites running, and I still feel that implementing the whole cocos2d framework is overkill
Mark