PDA

View Full Version : Approaches for making a sprite based game




SqueegyX
Jul 12, 2008, 01:59 PM
I want to make a simple sprite based game. Being new to the platform, I have 2 questions.


Is it best manipulate a bunch of UIImageViews or to simply draw things myself in a custom view's drawRect method?
Whats the standard way to create a main loop to redraw graphics every frame?


Thanks for the advice.



Yvan256
Jul 12, 2008, 02:27 PM
I want to make a simple sprite based game. Being new to the platform, I have 2 questions.


Is it best manipulate a bunch of UIImageViews or to simply draw things myself in a custom view's drawRect method?
Whats the standard way to create a main loop to redraw graphics every frame?


Thanks for the advice.

I have no idea but what I would do is a test with a huge meta-map (say, 1024x1024 tiles) and scroll around in a fixed pattern. Test with both methods and see the load it generates on the system.

If you can push things a bit by playing background music and playing a dozen sound effects at the same time, you could probably easily see which method is the best.

gralem
Jul 12, 2008, 09:16 PM
I would suggest that you use UIImageViews--as many as you want. In order to perform animation loops, you use NSTimer(s). You can look at the following example code from Apple: AccelerometerGraph, GLSprite, or CrashLanding.

NSTimers are very simple to establish. You often only need one animation cycle. If your entire set of animations can be performed in the same 30- or 60-hz loop, you need one timer to trigger your main loop.

You can also use UIView animations (not core animation) to handle "special cases", such as a single space ship flying across the screen during the game play. You could also use NSTimer, but UIView animations are simple and work great for one-off actions.

It really depends on what you are trying to accomplish. I have a puzzle game that does ALL of it's work via UIView animations, no NSTimers at all.

I would go through EVERY Apple sample code possible to see anything that is even close to what you're doing, and the dig into the SDK documentation (in XCode, go to Help -> Documentation).

Good luck. Let us know some more of what you are trying to accomplish, if you want more specific help.

---gralem

SqueegyX
Jul 13, 2008, 02:06 AM
Thanks. Some great advice in there. I greatly appreciate knowing which examples to poke in.

I sounds like if there was a whole lot of sprites doing crazy stuff, a custom view would be better, but as long as the UIImageView's arent so numerous to max out the CPU then it should be ok.

How, briefly, does UIImageView animations differ from an animation loop. Do you just tell it where to be in what amount of time and it just self animates? Sounds cool, but for most things having more direct control on each frame would be required for what I have in mind.

We'll see how this goes. Thanks again.

PhilipOrr
Jul 13, 2008, 02:36 AM
It will depends on the amount of images your after, and the complexity of the animation, and other work in the background.

If your after a puzzle game the UIImages are fine and can be animated with Core Animation. If your after anything else the you really should use OpenGL. Its hardware based and excellerated. It can handle thousands of images without much problems.

Large scrolling backgrounds really need to be in OpenGL too.

SqueegyX
Jul 14, 2008, 01:29 AM
If your after anything else the you really should use OpenGL. Its hardware based and excellerated. It can handle thousands of images without much problems.

Large scrolling backgrounds really need to be in OpenGL too.

That means I have to learn 2 things right now. I plan on messing around with the simpler stuff for a bit, get a feel for the iPhone SDK a bit more, then venture into OpenGL land.

Thanks for the great pointers in the right direction guys, really appreciate it.