Hi,
Ive been working with 2 projects since Xcode 3.2, using cocos2d 0.9. I ran through the complete RW SpaceViking Tutorial from Ray Wenderlich's new book and i made it through 3 scenes with box2d and debug draw. Then (in Xcode 4.0) i created my own game called PlanetHopper and successfully created a chipmunk and 2 box2d scenes again.
I started working on a new project, MZ, without box2d and then upgraded to Xcode 4.2 and upgraded to cocos2d 1.0. Now I finally upgraded to Xcode 4.3 last month and I added Box2d to my existing project, MZ, and i can run the scene just fine with the box2D import and .mm termination. It even runs fine with some basic box2d code such as:
- (void)setupWorld {
b2Vec2 gravity = b2Vec2(0.0f, -10.0f);
bool doSleep = true;
world = new b2World(gravity, doSleep);
}
- (void)setupDebugDraw {
debugDraw = new GLESDebugDraw(PTM_RATIO *[[CCDirector sharedDirector]
contentScaleFactor]);
world->SetDebugDraw(debugDraw);
debugDraw->SetFlags(b2DebugDraw::e_shapeBit);
}
- (void)createBoxAtLocation:(CGPoint)location withSize:(CGSize)size {
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position =
b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
b2Body *body = world->CreateBody(&bodyDef);
b2PolygonShape shape;
shape.SetAsBox(size.width/2/PTM_RATIO, size.height/2/PTM_RATIO);
b2FixtureDef fixtureDef;
fixtureDef.shape = &shape;
fixtureDef.density = 1.0;
body->CreateFixture(&fixtureDef);
}
-(id)init{
if ((self = [super init])) {
CGSize winSize = [CCDirector sharedDirector].winSize;
CCLabelTTF *label = [CCLabelTTF
labelWithString:@"Hello, Mad Dreams of the Dead!"
fontName:@"Helvetica" fontSize:24.0];
label.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:label];
/*
[self setupWorld];
[self setupDebugDraw];
[self scheduleUpdate];
self.isTouchEnabled = YES;
*/
}
return self;
}
-(void)update:(ccTime)dt {
int32 velocityIterations = 3;
int32 positionIterations = 2;
world->Step(dt, velocityIterations, positionIterations);
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [touch locationInView:[touch view]];
touchLocation = [[CCDirector sharedDirector]
convertToGL:touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
b2Vec2 locationWorld =
b2Vec2(touchLocation.x/PTM_RATIO, touchLocation.y/PTM_RATIO);
[self createBoxAtLocation:touchLocation
withSize:CGSizeMake(50, 50)];
return TRUE;
}
-(void) draw {
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
world->DrawDebugData();
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
- (void)dealloc {
if (world) {
delete world;
world = NULL;
}
if (debugDraw) {
delete debugDraw;
debugDraw = nil;
}
[super dealloc];
}
The only problem being the setupDebugDraw method above. With it I get 2 GLESDebugDraw::GLESDebugDraw(float) error...
If I remove the setupDebugDraw method it works fine.
I have checked them (.h & .m) vs the originals from SpaceViking & PlanetHopper & MZ and they are identical (using FileMerge). Im not sure what could be wrong with my GLES-Render files, or where the problem may lie. Could you help me out?
Ive been working with 2 projects since Xcode 3.2, using cocos2d 0.9. I ran through the complete RW SpaceViking Tutorial from Ray Wenderlich's new book and i made it through 3 scenes with box2d and debug draw. Then (in Xcode 4.0) i created my own game called PlanetHopper and successfully created a chipmunk and 2 box2d scenes again.
I started working on a new project, MZ, without box2d and then upgraded to Xcode 4.2 and upgraded to cocos2d 1.0. Now I finally upgraded to Xcode 4.3 last month and I added Box2d to my existing project, MZ, and i can run the scene just fine with the box2D import and .mm termination. It even runs fine with some basic box2d code such as:
- (void)setupWorld {
b2Vec2 gravity = b2Vec2(0.0f, -10.0f);
bool doSleep = true;
world = new b2World(gravity, doSleep);
}
- (void)setupDebugDraw {
debugDraw = new GLESDebugDraw(PTM_RATIO *[[CCDirector sharedDirector]
contentScaleFactor]);
world->SetDebugDraw(debugDraw);
debugDraw->SetFlags(b2DebugDraw::e_shapeBit);
}
- (void)createBoxAtLocation:(CGPoint)location withSize:(CGSize)size {
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position =
b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
b2Body *body = world->CreateBody(&bodyDef);
b2PolygonShape shape;
shape.SetAsBox(size.width/2/PTM_RATIO, size.height/2/PTM_RATIO);
b2FixtureDef fixtureDef;
fixtureDef.shape = &shape;
fixtureDef.density = 1.0;
body->CreateFixture(&fixtureDef);
}
-(id)init{
if ((self = [super init])) {
CGSize winSize = [CCDirector sharedDirector].winSize;
CCLabelTTF *label = [CCLabelTTF
labelWithString:@"Hello, Mad Dreams of the Dead!"
fontName:@"Helvetica" fontSize:24.0];
label.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:label];
/*
[self setupWorld];
[self setupDebugDraw];
[self scheduleUpdate];
self.isTouchEnabled = YES;
*/
}
return self;
}
-(void)update:(ccTime)dt {
int32 velocityIterations = 3;
int32 positionIterations = 2;
world->Step(dt, velocityIterations, positionIterations);
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [touch locationInView:[touch view]];
touchLocation = [[CCDirector sharedDirector]
convertToGL:touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
b2Vec2 locationWorld =
b2Vec2(touchLocation.x/PTM_RATIO, touchLocation.y/PTM_RATIO);
[self createBoxAtLocation:touchLocation
withSize:CGSizeMake(50, 50)];
return TRUE;
}
-(void) draw {
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
world->DrawDebugData();
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
- (void)dealloc {
if (world) {
delete world;
world = NULL;
}
if (debugDraw) {
delete debugDraw;
debugDraw = nil;
}
[super dealloc];
}
The only problem being the setupDebugDraw method above. With it I get 2 GLESDebugDraw::GLESDebugDraw(float) error...
If I remove the setupDebugDraw method it works fine.
I have checked them (.h & .m) vs the originals from SpaceViking & PlanetHopper & MZ and they are identical (using FileMerge). Im not sure what could be wrong with my GLES-Render files, or where the problem may lie. Could you help me out?