Game Development Reference
In-Depth Information
hierarchy, and moving the Spider object would no longer move the spiderS-
prite .
Listing 5-12. The Spider Class Implementation
#import "Spider.h"
@implementation Spider
// Static initializer, mimics cocos2d's memory allocation scheme.
+(id) spiderWithParentNode:(CCNode*)parentNode
{
return [[self alloc] initWithParentNode:parentNode];
}
-(id) initWithParentNode:(CCNode*)parentNode
{
if ((self = [super init]))
{
[parentNode addChild:self];
CGSize screenSize = [CCDirector sharedDirector].winSize;
spiderSprite = [CCSprite spriteWithFile:@"spider.png"];
spiderSprite.position = CGPointMake(CCRANDOM_0_1() * screenSize.width, ←
CCRANDOM_0_1() * screenSize.height);
[self addChild:spiderSprite];
[self scheduleUpdate];
}
return self;
}
-(void) update:(ccTime)delta
{
numUpdates++;
if (numUpdates > 60)
 
Search Nedrilad ::




Custom Search