misterbrownstone
misterbrownstone

Reputation: 111

How do I add background in cocos2d?

I'm a total noob. Starting my first app. I'm using cocos2d and there's isn't a .xib file so how do I add a background image behind the sprites I have in my scene?

Upvotes: 0

Views: 1171

Answers (1)

pabloruiz55
pabloruiz55

Reputation: 1306

In Cocos2d you don't use xibs you have to place all the objects by code. Check the samples that come with Cocos2d to get a sense of how it works. If you already know how to add sprites, adding a background is done the same way, it would be just another sprite just add it with a lower z-order.

[self addChild:myBackground z:0];

"self" would be the actual CCLayer

"myBackground" the sprite you created with the bakcground iamge.

and "z" would have to be lower than the z used for the other elements.

Upvotes: 1

Related Questions