CCSprite
In cocos2d game development, CCSprite is one of our best pals. It is a class which uses an image to display the sprite onscreen. To create a sprite, we first load an image file into a CCTexture2D texture and then assign this texture to the sprite. We will also need to make sure that this image file has been added into the Resources group in Xcode so that our app will be able to find the file. So here’s an example of how our sprite is instantiated:
CCSprite* sprite = [CCSprite spriteWithFile:@"Default.png"] [self addChild:sprite];
When our sprite in instantiated, the texture is centered in the sprite’s position and the sprite which has just been initialized will be located at position 0,0 – the lower left corner of the screen. Because the sprite’s texture is centered on the sprite’s position, the texture will be only partially visible. Assuming that the image is 60 x 30-pixels in size, we will have to move our sprite to position 30, 15 to make the texture align perfectly with the lower left corner of the screen and be fully visible.
The other important point to note is that file names are case sensitive in iOS. So if our file name is “Default.png”, it has to be spelled exactly that to avoid your app crashing inexplicably.