Core Animation Architecture in Games - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: Core Animation Architecture in Games (/thread-8796.html)
Core Animation Architecture in Games - Mattonaise - Apr 6, 2011 10:35 AM
I am new to this forum and to iphone development in general, so any helpful tips would be much appreciated.
My question is about using CALayers in simple 2d games, and about their performance as well. The design of the game in my head is very simple graphics-wise, so I think CALayers would be able to handle it. There is only going to be about 8-9 objects moving on the screen at any one time, so not very complex (no particles or animations either). I just want some input on if this would be acheivable easily with CALayers, as Opengl ES would take up too much of my time to implement right now...
The implementation of CALayers also brings up a few questions. I wouldn't subclass CALayer to create the game object classes, as I am planning to keep the game entities and data away from the CALayers to keep the code as clean and flexible as possible. What I mean is to have a seperate class holding the game data, and keep the CALayers for the game objects in a game UIView subclass. The game UIView subclass would have a reference to the game data instance (they could possibly both exist in a uiviewcontroller class, MVC?), so that every time the screen needed to be updated, the view could look up coordinates of game objects in the game data instance and set the CALayer coordinates to match that. I am planning to have different "themes" in the games for the graphics (neon, doodle, space, underwater,...), so I thought this architecture would let me change the images pretty easily. Another thing is that if this app was to become Universal, I would only need to have a different subclass of the game UIView (one for iphones, another for retina display, and one for ipad) and only need to change the game data class slightly (really just screen sizes and coordinates) in order to be able to run the app on different devices. Is this a good and flexible way to approach the architecture of the code? Any advice is very helpful.
However, one question about this architecture is that whether it would be better to update the CALayer coordinates every frame (and possibly need to use setneedsdisplay?) or to use an animation from one place to different coordinates 5 frames later, as the first option may cause performance difficulties. But there is some simple circle-to-circle physics in the game, so animations from place to place may not look so realistic. Again, any input will be helpful.
I hope the post was easy to follow , i tried to cram a lot of stuff in there so Im not sure if it was explained very well. So feel free to ask me any questions you may have.
RE: Core Animation Architecture in Games - OneSadCookie - Apr 6, 2011 10:44 AM
Performance should be fine. Unless you already know your way around CA, OpenGL ES may not be any harder to learn
Your design sounds reasonable.
You'll want to turn off the implicit animations and manually control the layers' transformations.
RE: Core Animation Architecture in Games - SethWillits - Apr 6, 2011 12:17 PM
No, explicit animation won't have a performance hit.
And, welcome. You already seem to be one the most intelligent 14 year olds we've seen in a while. You remind remind me of myself at that age
RE: Core Animation Architecture in Games - Mattonaise - Apr 6, 2011 03:56 PM
Ahh, thank you!
Okay I think Core Animation will work fine for the project. Does anyone have any experience with Universal apps? I think my game would work well as an ipad app as well, so i think that may be a good idea. What would the architecture require to easily allow itself to be universal? maybe different UIViews? I could have different subclasses of UIViews, one for iphone and another for ipad, but the game would be similar on both the ipad and iphone so different subclasses may not be needed and may have too many similarities to the other to be useful enough. Does anyone have any hints on the subject?