官术网_书友最值得收藏!

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 scene. From the Resources folder of the chapter, we will drag the Bg-ipad.png and Bg-ipadhd.png files into the Resources/Published-iOS folder of the project.

We still have to make a small change in the CCBReader.m file. In the Search inspector, search for the CCFileUtilsSearchMode text, and in place of CCFileUtilsSearchModeDirectory, make the text CCFileUtilsSearchModeSuffix.

This will change the searchmode file from the folder to suffix mode.

How it works…

If you build and run now, you will see an image similar to the following screenshot. This way, we can display sprites on the scene.

主站蜘蛛池模板: 乌什县| 渑池县| 涞源县| 土默特右旗| 西华县| 珲春市| 图片| 礼泉县| 遵义县| 高台县| 信宜市| 盘山县| 通江县| 林西县| 盐源县| 牡丹江市| 象州县| 高雄市| 樟树市| 皮山县| 海城市| 醴陵市| 深水埗区| 阿荣旗| 广元市| 澄城县| 托里县| 云林县| 临夏县| 新竹市| 正宁县| 陇西县| 博乐市| 清涧县| 郧西县| 万山特区| 西峡县| 湘阴县| 肇州县| 伊宁县| 永平县|