O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding sprites to scenes

To display any image onscreen and manipulate it, you will need to add it to the scene using the CCSprite class. Unlike a regular image, a sprite has properties such as move, scale, rotate, and so on, which can be used to manipulate the image.

Getting ready

To add sprites to the scene, we will first import the background image in to our project.

How to do it…

Add the following code to the init function right below where we added backgroundColorNode:

//Basic CCSprite - Background Image

CCSprite* backgroundImage = [CCSpritespriteWithImageNamed:@"Bg.png"];

backgroundImage.position = CGPointMake(winSize.width/2, 
  winSize.height/2);
[selfaddChild:backgroundImage];

Here, we will take the Bg image and add it as a child to the current ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required