- Cocos2d Cross-Platform Game Development Cookbook(Second Edition)
- Siddharth Shekar
- 210字
- 2021-07-16 09:43:45
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.

- DB2 V9權(quán)威指南
- 編寫高質(zhì)量代碼:改善Python程序的91個(gè)建議
- HBase從入門到實(shí)戰(zhàn)
- 西門子S7-200 SMART PLC編程從入門到實(shí)踐
- Creating Stunning Dashboards with QlikView
- Java程序設(shè)計(jì)案例教程
- JBoss:Developer's Guide
- Python機(jī)器學(xué)習(xí)算法與應(yīng)用
- Maker基地嘉年華:玩轉(zhuǎn)樂(lè)動(dòng)魔盒學(xué)Scratch
- Zabbix Performance Tuning
- Java EE架構(gòu)設(shè)計(jì)與開發(fā)實(shí)踐
- R語(yǔ)言實(shí)戰(zhàn)(第2版)
- Python繪圖指南:分形與數(shù)據(jù)可視化(全彩)
- 軟技能2:軟件開發(fā)者職業(yè)生涯指南
- Python深度學(xué)習(xí)與項(xiàng)目實(shí)戰(zhàn)