Core Animation Architecture in Games

Member
Posts: 27
Joined: 2011.04
Post: #1
Hello forum...
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.

A 14 year old app developer...god help me...
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Performance should be fine. Unless you already know your way around CA, OpenGL ES may not be any harder to learn Rasp

Your design sounds reasonable.

You'll want to turn off the implicit animations and manually control the layers' transformations.
Quote this message in a reply
⌘-R in Chief
Posts: 1,252
Joined: 2002.05
Post: #3
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 Wink
Quote this message in a reply
Member
Posts: 27
Joined: 2011.04
Post: #4
Ahh, thank you! Grin

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?

A 14 year old app developer...god help me...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Help With Universal Game Architecture? Mattonaise 1 3,154 Apr 7, 2011 04:06 PM
Last Post: Mattonaise
  Checking for architecture? Bersaelor 2 2,667 Sep 20, 2010 11:56 AM
Last Post: Rasterman
  OpenAL and Build Active Architecture Only Madrayken 2 3,205 Jul 8, 2009 02:53 PM
Last Post: Madrayken
  What's wrong with Core Graphics and UI? Lazarwulf 1 3,210 Nov 12, 2008 12:33 PM
Last Post: longjumper
  2D Game/App, Core Graphic matax 1 3,489 Aug 26, 2008 06:36 AM
Last Post: ThemsAllTook