Game Development Reference
In-Depth Information
Think of the CCSpriteBatchNode as similar to a CCLayer , except that it only ac-
cepts CCSprite nodes using the same texture. With that mind-set, I'm sure you'll
find the right places to use the CCSpriteBatchNode .
The Sprites01 Demo Project
This project demonstrates how to use CCSpriteBatchNode . Let's take the first
steps toward the scrolling shoot-'em-up game in Chapters 7 and 8 . Because developers
often start by using just the CCSprite node and then improve the code to support
CCSpriteBatchNode , I found it interesting to show this process exactly and how
the code changes along the way.
The project uses two classes— Ship and Bullet , both derived from CCSprite —to
illustrate how you can change a project from using regular CCSprite objects to a
CCSpriteBatchNode .
A Common and Fatal Mistake
Before I begin, I want you to know about a common trap developers new to Objective-
C can quickly find themselves in. It's easy to make this mistake but hard to figure out
the cause and how to fix it. I fell into this trap myself once. Take a look at Listing 6-2 ;
do you see what's wrong with this code?
Listing 6-2. A Commonly Made Fatal Mistake When Subclassing CCSprite (or Other
Classes for That Matter)
-(id) init
{
if ((self = [super initWithFile:@"ship.png"]))
{
[self scheduleUpdate];
}
return self;
}
 
 
Search Nedrilad ::




Custom Search