iPhone development using sprites - iphone

I want to create an iPhone/iPod game. I want it to be 3d, but I want to use sprites instead of OpenGL to do this (I assume this would be easier since I don't know OpenGL).
I was thinking of simply layering sprites over top of each other and changing their size to give an illusion of 3d. It doesn't need to be too convincing since the game will be somewhat cartoony.
How can I use sprites as an alternative to OpenGL on the iPhone platform?

You can use CoreAnimation for this. Either using UIImageViews (or plain UIViews) or CALayers.
It's usually the best choice for some types of 2d games (board games, for example), since animation, rotation and scaling are really easy. Just keep in mind that if performance is your concern, OpenGL will always be better.

Depending on how much 3d, I'd recommend taking a look at cocos2d. It supports multiple layers, sprites, animations, etc, but is pretty straightforward to pick up & learn. (Much easier than OpenGL to me) The example code is very comprehensive.
http://code.google.com/p/cocos2d-iphone/

I have built a game using core animation with upto about 17 - 20 objects floating about the screen scaling and rotating and performance was fine on the iPhone (make sure you check regularly on the iPhone as the simulator doesnt simulate iPhone memory or CPU speed).
CoreAnimation is pretty simple and really powerful. Use PNG's for images and I don't think you will have to many issues. The real killer of this will be alpha's in your images, this is hard work for the iPhone. So the less transparency you have the better you app will go.

In addition to Marco's answer I want to add: Not using OpenGL may also tax the device battery a little more. As I understand it, OpenGL ES can be more efficient on a device power supply (if implemented properly). Of course, this depends on how much animation is going to be used with UIImageView, UIView or CALayers, etc.
I'm sure there is a tipping point.

Related

Applicable iPhone graphics library

I've tried reading up on Core Animation, Quartz, OpenGL, and cocos2d. While I think I have a feeling what they're all meant for, I still can't decide what's appropriate for the project I'm undertaking. The requirements are straight forward, I need to be able to import a custom font and draw it. I need to draw lines and arcs.
I tried using OpenGL ES for this, but it was very hard to work in custom fonts. Between Quartz and Core Animation, I'm not sure what's applicable. The application will always be in 2D. Performance is important. I have a feeling Quartz might not be appropriate since you can use a finger swipe to move the screen to a different part of the content and it seems that redrawing that much content with Quartz is heavy on the GPU. Not sure though, this is all from reading.
The outlier is cocos, since it seems to fit into a couple different buckets. It seems closer to OpenGL, but without the insanity when it comes to loading in custom fonts. There didn't seem to be enough info to get a feel for whether it would fit for this project though.
I have pretty extensive experience with both Corona and Cocos2d. Corona is easy to use and great for a beginning programmer. There's a fairly large class of apps that you can write in Corona, but if you're looking for high performance, your best bet is Cocos2d. There's practically no 2D app you can think of that can't be written in Cocos2d. I recommend Steffan Itterheim's book if you're interested in learning it.
Best of luck!
Sounds like you need Ansca Mobile's Corona and x-pressive.com's Text Candy library:
Corona SDK
Text Candy

iPhone. Particle system performance

I try to draw rain and snow as particle system using Core Graphics.
In simulator rendering proceeded fine but when I run my app on real device rendering is slow down.
So, advise me please approaches to increase particle system drawing performance on iPhone.
May be I should use OpenGL for this or CoreAnimation?
OpenGL would be the lowest level to drop to for the rendering, so should offer the best performance (if done right). CoreAnimation would be close enough if there are not too many particles (the exact figure depends on other factors, but upto about 50 should be ok).
When you say you're using CoreGraphics at the moment do you mean you're redrawing based on a timer? If so then CoreAnimation will definitely help you out - as long as you can seperate out each particle into a view. You could still use CoreGraphics to render the individual particles.
Are you using a physics engine to calculate the positions?
If you are simply drawing a view with Core Graphics, then redrawing it every frame to reflect the movement of the particles, you will see terrible performance (for more, see this answer). You will want to go to OpenGL ES or Core Animation for the particle system animation.
My recommendation would be to look at CAReplicatorLayer, a new Core Animation layer type added in iPhone OS 3.0 and Snow Leopard. I've seen some impressive particle systems created just using this one layer type, without using much code. See the ReplicatorDemo sample application (for the Mac, but the core concepts are the same), or Joe Ricioppo's "To 1e100f And Beyond with CAReplicatorLayer" article.
It's hard to give advice with little to no information about your implementation. One thing that is a major bottleneck on the iPhone from my experience are memory allocations. So if you're allocating new objects for each particle spawned, that would be the first thing you might want to fix. (Allocate a pool of objects and reuse them.)

Core Animation or OpenGL for simple iPhone game

I am writing a simple game that animates a ball image quickly across a background image.
Would Core Animation/Quartz be sufficient for this scenario?
I don't really want to learn OpenGL ES if it is not going to provide any substantial benefit in this one off project.
This is a commonly asked question. Other questions like this include:
"iPhone board game: OpenGL ES or CoreGraphics?"
"Are most games on the IPhone done with OpenGL ES?"
"Core Animation or OpenGL ES?"
"Does openGL ES have a better performance than Core Animation and UIKit when it comes to highly animated user interfaces?"
OpenGL ES I suppose isnt too hard.
But at the end of the day Core Animation is going to be fine, its super powerful and not to hard to work with. It will also get you up and running so quick that you will release you game "sucks" a bit and you want to change it and you didn't even have to learn OpenGL.
I highly recommend looking at cocos2d. A very simple game engine for 2d stuff.
http://cocos2d.org/
Have a look at that.
Cheers, John
OpenGL ES isn't that hard, there are lot of really good resources in the web and step by step tutorials. Can be hard at first, but once you get the grip of It things will be easy. 71 Squared has very detailed tutorials:
http://www.71squared.co.uk/iphone-tutorials/
About the question, Core Animation Is great for most apps, but in a videogame It's fundamental to draw your game efficiently and have as much control as possible.
Cocos2d Is great and I recommend It If you need to write a good game, but if you're doing It for educational purposes I recommend OpenGL, You will learn a lot with It and gain a lot of experience.
Just jump to something like Cocos2D so that the OpenGL is done for you. OpenGL ES is significantly faster and more adaptable than Quartz, plus it's not any harder. I even think Quartz is a big pain in the butt and difficult to figure out, although I came from an OpenGL background on desktop computers first, so naturally that jump is pretty small. The point is, though, that either with Quartz or with OpenGL ES you're going to need to spend a lot of time with resource management, etc., so you might as well go with Cocos2D.
yes, it will be fine, as long as you're not wanting to do hundreds of balls at once or something else complicated like that.
If your knowledge of Core Animation is good then i recommend you to skip learning OpenGL ES for now, since it won't really help you (if all you want is what you described of course). On the other hand, if you plan to make more games which have more involved graphics, it might be a better idea to start learning the API. OpenGL ES is a simple API and you can use the full graphics features of the iPhone with it.
If all you want to do is just make this game, then i say go with what you know and are productive.
I would say this very much depends on what you want to do with the ball. If you simply want to fire off an animation and forget about it Core Animation will probably be fine. However, if you are trying to interact with the ball, for example by changing the direction of the ball mid-flight based on user interaction, then you probably want to consider OpenGL ES. Of course, you're other option is to use neither Core Animation or OpenGL ES and simply redraw your view on a timer.
If you're a fairly competent C programmer I wouldn't be too put off the OpenGL ES stuff. Apple supply a lot of the framework for hosting OpenGL ES views in their templates. Although OpenGL can get fairly involved, if you're not trying to render huge multi-object 3D scenes then the basics are fairly straightforward and you should be able to get some nice results quite easily. Although it is for OpenGL rather than OpenGL ES, I would recommend this set of video demos as a good starting point:
www.videotutorialsrock.com

Is OpenGL required for my iPhone game?

On an iPhone:
If I am writing a game that has multiple levels, with multiple animations (image sequences), jpg and png (transparent), some full screen and some not, some looped and some played once only. What is the best way of doing it? Each level might have up to 10MB of images. Add on to this music, and video (cut scenes). All 2D graphics, no 3D models.
Is OpenGL required? Or can this be achieved with Quartz or Core Animation?
I do similar using UIViews and a bit of Core Graphics (Quartz 2D) and it works fine. I've found the custom drawing in Core Graphics pushes it a bit further, tho - UIViews work best when given images rather than having to draw themselves. Also watch out for lots of transparencies. You'll probably find that large or long (many frame) animations will be the killer, though. There are some techniques for minimising the impact of the animations which involves allowing it to purge images from memory if not being immediately displayed (I forget the setting). This may result in your animations not being as smooth as you they would otherwise be (not sure if Open GL ES would help here, though).
You should probably prototype using UIViews, and decide then if it's worth doing the extra work for OpenGL ES. Also, if you're not already familiar with OpenGL/ Open GL ES it's a steep learning curve.
I've used both Quartz and OpenGL to do graphics on the iPhone, and while OpenGL has a much higher learning curve, it gives much better performance than Quartz. Let's say you have a scene that involves drawing 6 large, semi-transparent images on top of each other. Quartz will do it, but you'll probably get 15fps at best. OpenGL takes advantage of the iPhone's PowerVR chip and the drawing is hardware accelerated - so you can load those images into OpenGL textures and render at 25-30fps no problem.
I would agree with Phil though - try doing it using Quartz and see if it meets your needs. OpenGL is extremely powerful but it's API lacks some of the convenience features of Quartz (such as saving/restoring graphics state).
One another note entirely, you might want to take a look at Unity's iPhone development tools (http://unity3d.com/#iphone). They leverage OpenGL but provide you with an IDE to create your game. It abstracts away all of the graphics-level code, so you can focus on the high-level gameplay. My brother uses it to write iPhone games, and it's extremely cool.
I recommend having a look at Cocos2D iPhone.
cocos2d for iPhone is a framework for building 2D games, demos, and other graphical/interactive applications. It is based on the cocos2d design: it uses the same API, but instead of using python it uses objective-c.
Most likely OpenGl.
One advantage of using OpenGL ES would be that the investment of time for learning the technology could be applied to other platforms/contexts and your game is potentially more port-friendly. These may not be important to you.
I would suggest using Quartz. OpenGL ES is really best for 3d stuff. However both work fairly well, so if you already know OpenGL ES, it's fine to use that.
You should consider using a lot of less resources in your game, Apple recommends not to use more than 10 mb in texture for openGL apps.
Try texture atlas, reuse graphics, tile based graphics...but avoid to use to much graphic assets.

iPhone: Quartz2d vs. OpenGL ES

OK, I'm still brand new to iPhone development. I have a free game on the app store, Winner Pong, but it's just a Pong clone (who would've guessed) that uses the standard UIImageViews for the sprites. Now I want to do something a little more complicated, and port my game for the Xbox 360, Trippin Alien, to the iPhone. I obviously can't keep using UIImageViews, so I was wondering which would be better to learn: the simpler, but performance-hindering Qurtz2D, or the smooth-running but dauntingly complex OpenGL ES.
My game is basically a copter game, with about 8-10 sprites on screen plus a simple particle system (video here). Not too complicated, but performance does matter. My only prior game programming experience is in Microsoft's XNA and C#, which has a built in SpriteBatch framework that makes it incredibly easy to draw, scale, and rotate pre-rendered sprites on screen. Is it worth it to learn OpenGL ES? How big is the performance gap? Is quartz really that simple?
Also, if anyone knows of any tutorials for either one, please, post them here. I need as much help as I can get.
Look through code samples of each to actually see the complexity. You might find that OpenGL isn't so daunting.
Regarding the performance. Core Animation, which Quartz2d is part of, uses OpenGL behind the covers, so for simple sprite animations, I would expect your game to perform fairly well.
I would also glance over the programming guide for each before making your final decision.
Another alternative is to use something like Unity. I recently just started playing around with the trial version of this development environment and if you're mostly doing game development with graphical objects and sprites, this may be one option to consider. You can script in C#, Javascript, or Boo. The development environment allows you to graphically setup your scenes and levels. You can then attach scripts to graphical objects for animation to handle user events, etc.
One downside for Unity, which I've heard from others is that if you want to use the familiar UI controls from UIKit, it's not so easy to instantiate them...I haven't verified this myself.