infinite Loop Problem in Cocos2d

Forums Programming cocos2d support (graphics engine) infinite Loop Problem in Cocos2d

This topic contains 1 reply, has 1 voice, and was last updated by  GPP 2 years, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
Author Posts
Author Posts
January 18, 2012 at 7:57 pm #238512

GPP
@gpp

I am working on getting a Bullet engine integrated with the Player class code, so the Player class can call BulletCache methods.

My integration so far consists of creating a BulletCache object in the Player class’ interface e.g.:

@interface Player : LevelObject
{
BulletCache *bulletCache;
}

And I also added in the Player init method:

-(id)init
{
self = [super initWithTitle:@"barbarian king"];
if(self != nil)
{
// give ourselves a tag so other nodes can find us
// (we don't have a tag because Level adds us without one)
self.tag = kTagPlayer;

//initialize bulletCache in Player class
bulletCache = [BulletCache node];
//Other methods...
}

However, the bulletCache = [BulletCache node]; call produces an infinite loop when I start a new game from the main menu layer.

I enabled breakpoints, and checking the console yielded this message:

Assertion failure in -[Bullet initWithSpriteFrame:], /Users/Username/Desktop/Directory/
Quexlor/../src/cocos2d-iphone-0.99.4/cocos2d/CCSprite.m:231

I get a non-NSAssert message: non-NSAssert msg:

cocos2d: CCSpriteFrameCache: Frame 'bullet1big e0000.png' not found

Question: Is this infinite loop caused by the game’s failure to locate and load the BulletCache’s images?

January 18, 2012 at 9:38 pm #362604

GPP
@gpp

So I did a breakpoint check on the program, and on two separate occasions, I put two break points in two different methods of the Bullet and BulletCache classes.

-(id) initWithBulletImage
{
// Uses the Texture Atlas now.
if ((self = [super initWithSpriteFrameName:@"bullet1big e0000.png"]))
{
}

return self;
}

The Breakpoint was place on the same line as the ‘if ((self’ code

And the message displayed in the console read: GDB:Stopped at breakpoint 1 (hit count: 3) ‘-initWithBulletImage – Line 29′

This method is in the Bullet class.

The second Breakpoint I put (in a different Build & Run of the Program) was in the BulletCache class and it is the BulletCache’s init method:

-(id) init
{
if ((self = [super init]))
{
// get any bullet image from the Texture Atlas we're using
CCSpriteFrame* bulletFrame = [[CCSpriteFrameCache sharedSpriteFrameCache]
spriteFrameByName:@"bullet1big e0000.png"];
// use the bullet's texture (which will be the Texture Atlas used by the game)
batch = [CCSpriteSheet spriteSheetWithTexture:bulletFrame.texture];
[self addChild:batch];

// Create a number of bullets up front and
//re-use them whenever necessary.
for (int i = 0; i < 200; i++)
{
Bullet* bullet = [Bullet bullet];
bullet.visible = NO;
[batch addChild:bullet];
}
}
return self;
}

Placing the breakpoint on the line of the statement:

CCSpriteFrame* bulletFrame = [[CCSpriteFrameCache sharedSpriteFrameCache]
spriteFrameByName:@"bullet1big e0000.png"];

yielded this message displayed on the bottom of the console:

“GDB: Stopped at breakpoint 1 (hit count: 1) -’-init-Line 84′ “

So it looks like the crux of the issue is that the game can’t seem to find bullet1big e0000.png

Thing is though, the bullet1big.png is a texture made by Zwoptex, and bullet1big e0000.png is a frame within that texture that I called because I haven’t yet written code that assigns each frame (total of 8 bullet frames in that texture) to the direction of the player (i.e. player is facing north and fires, north bullet frame is drawn)

This really is a confusing issue for me folks, I’d appreciate some help!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.