Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

SqueegyX

macrumors regular
Original poster
Mar 24, 2008
108
1
I want to make a simple sprite based game. Being new to the platform, I have 2 questions.

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

Thanks for the advice.
 

Yvan256

macrumors 603
Jul 5, 2004
5,119
1,079
Canada
I want to make a simple sprite based game. Being new to the platform, I have 2 questions.

  1. Is it best manipulate a bunch of UIImageViews or to simply draw things myself in a custom view's drawRect method?
  2. 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

macrumors member
Mar 25, 2002
48
0
Suggestion

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

macrumors regular
Original poster
Mar 24, 2008
108
1
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

macrumors member
Nov 7, 2007
42
0
Northern Ireland
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

macrumors regular
Original poster
Mar 24, 2008
108
1
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.