views:

81

answers:

2

I have 3 nice and puffy clouds I made in Photoshop, all the same size, now I would like to animate them so they appear like they were moving in the background. I want this animation to be the base background in all my scenes (menu,settings, score, game).

I'm using cocos2d, I have setup the menus and the buttons so the work but how do I accomplish this?

I was thinking to add this as a layer, any other suggestions?

Can anyone show me how some code how to make this please?

David H

A: 

A simple way to do it is with sine and cosine. Have slighly different parameters (period and amplitude) to ensure that the user doesn't realise (as easily) that they are programmatically animated.

You may also want to play with animating the opacity value. I'm not sure if layers have those, otherwise you'll have to add the clouds to separate nodes or images and applying it to them.

It's hard to be more specific without knowing what the images look like.

Srekel
The Images are the same (125x75px) size with transparent background. I made them of a bunch of circles, they have a cartoonish look.
David Holmes
A: 

The simplest way to animate anything is to add the sprite to the scene, set the position and call something like...

[myClouds runAction:[CCMoveBy actionWithDuration:10 position:CGPointMake(200, 0)]];

This will slide the sprite 200px to the right over 10 seconds. As Srekel suggested, you can play around with some trig functions to get a more natural feel and motion paths, but you'll have to schedule a selector and iteratively reposition the elements.

The more difficult part of your questions is about getting the animation in the background of all scenes. Keep in mind that when you switch scenes, you're unloading one node hierarchy and loading a new one. The background cannot be shared. You CAN, however, duplicate the sprites and animation in all scenes, but when you transition between them there will be a jump.

jtalarico