Animating large sprites with cocos2d (ccspritesheet) - iphone

I'm working on an iPhone game using Cocos2d where the main character is approximately 194x114.
the animation consists of 100+ frames making my spritesheets larger than the 1024x1024 limit. The obvious solution would be to separate the animation to several files and swapping spritesheets when necessary. while doable (i guess) i'm not quite sure how to go about implementing this solution, is there a better solution? what is your experience with large animation with Cocos2d?

Yes, your best bet (and only option, really) is to break up separate animations into separate files. One strategy is to create a helper class that knows which animations live in which source files and swap between them, so your main code can worry about picking the animation and not messing with specific source file names.
I suspect you may be getting confused by CCSprites being added as a child of a CCSpriteSheet. When swapping between sheets to change animations, just remove the sprite from one CCSpriteSheet and add it to the CCSpriteSheet containing the new animation.

Related

Using unity animations globaly

I am trying to code an end for a level in a simple game. A lot of things need to happen at slightly different times. The character needs to do a celebration. Text needs to pop up on screen. The camera needs to move to show off the win, and finally there needs to be a scene transition.
This all seems like a great thing to solve with an animation. All these things could come in and act on specific key-frames, at the end raising an event and ending the scene.
The problem is it looks like animations have to be attached to specific objects. My camera, player, and the static global GameController are completely unrelated. In fact the global controller can't be related to anything. Because of that my animations don't see all the objects and can't control them. I am instead stuck writing synchronized animations, and code with a lot of yield return new WaitForSeconds(...);. I find this very difficult to manage, and seems like a lot of waste. Is there any way I can use animations, or some other frame based tool to globally animate my game?
Look into Unity's Timeline system. I believe this is exactly the sort of thing it was made for.

Sprites for iOS devices

I'm trying to do a little research for my next game that I'm planning to make and just wondering if anyone could give me a little direction.
I'd like to use sprites to show animation, characters walking and such so my question is this. What game engine handles sprites the best?
And how many sprites can be shown per second? Say i had a character walking and wanted it to look pretty fluid, might i be able to get 60fps? or is that way way to high?
Last question.. sorry! If a sprite has more colors and complexity, but is the same file size as something simpler would it take more processing power to display the complex one?
thanks!
James.
I would highly recommend cocos2d for sprite animations. It's very easy to pick up if you already know objective-c. And it's great for working with sprites. The animations are very fluid and when your testing your applications in an iOS simulator, it tells you the frames per second in the bottom left hand corner. The frames per second usually runs at about 60. And regarding the sprite file size, I believe if the file size is the same between two sprites then they require the same amount of processing power.
A good engine to use for it's simplicity is the Sparrow engine for sprites, sound and other things. There is no reason you can't get 60fps. As for your last question, it wouldn't make a difference.

Equivalent of -viewDidAppear for CCLayer?

Question:
In the realm of cocos2d for iPhone, what's the equivalent of UIKit's -viewDidAppear callback for CCLayer?
*And if no equivalent exists (as seems to be the case in the docs), what's your recommended way knowing when a CCLayer has been rendered?
There are these two methods which are quite similar to
- (void)onEnter;
- (void)onEnterTransitionDidFinish;
Well, a CCLayer is rendered, usually, when it is created and you add sprites to it. You should do all this up front before the game play begins. Then you can move the layer around and animate its objects without worrying about "when" it will be finished rendering (usually).
Scenes are a different matter. A scene is what sets up the layers and creates them, loads images, sprites, etc, and tha can take a bit. For that you have a few options. One effective option is the the onEnter and onExit family of methods. However, another really good way is to simply have an intermediate scene, such as a mostly empty, lean Loading CCScene that you load, and then that scene loads the big scene you are trying to load. When you do this, you are freeing up old memory before adding new memory.
It really depends on what you are trying to accomplish with your equivalent of viewDidAppear.

Dynamic animation using mic volume as trigger

I am new to iPhone development, and I am looking for someone with experience
to simply tell me whether I am on the right path or to perhaps point me to it
regarding what I am trying to acheive.
I am trying to develop a character animation that reacts to the volume of
the microphone input. Something like Talking Tomcat, except that instead of
having just a face react to the volume, an entire character´s body is involved.
The character has been created in illustrator and it is image based. So
this will be a 2D animation. I have created numerous frames for the different
kinds of reactions the character will have depending on the volume.
For my animation I am using UIViews using its Animation resources and adding
UIImageViews as subviews. I am also using CGAffineTransforms for rotating
images.
I am also relying on Timers to control the different stages of the
animation.
To allow for a more flexible animation, I have created UIViews for the head,
arms, torso and legs of the character. These have been severed into their own
images and I am manipulating these images individually through UIViews.
I can go over my code in more detail if necessary, although any help will be greatly appreciated even if it is something off the bat.
Seeing that you're not an advanced ios developer I would suggest starting with cocos2d.
It has everything you need to start with animation.
Web page and forums has plenty of information on how to do it and... what's most important [to me at least], you've got gurus like Ray Wenderlich writing excellent tutorials like:
http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d

Performance Gain Using Multiple CALayers in One UIVew

I'm in the process of writing a simple 2D game which at present does a fair bit of custom drawing for multiple sprites upon each update - i.e. I have game view that delegates to all sprites to perform quartz rendering (point/line based) upon each update.
My performance is ok upto around 50 active objects being rendered but now things are starting to slow down so I'm looking to optimize. To do so I've decided to pre-render my sprites to a CALayer then add that to the game view.
My first thought was to give each Sprite instance a CALayer which is added to the GameView's view.layer as sublayer. This would mean that I use a single UIView which has multiple CALayers - one per game sprite.
Would there be a negligible performance loss if I decided to use a UIView for each game sprite?
UIViews are part of the responder chain and will add extra overhead. I started with UIViews for sprites and found gestures became sluggish.
I would recommend sticking with CALayers
As far as I know, UIViews are pretty lightweight wrappers around CALayer, so the performance loss shouldn't be too big. But I think a sprite would simply be better represented by an instance of CALayer rather than UIView.