我是自定义调试 - 在我的游戏中绘制物理形状。在我升级到cocos2d 2.0,iOS 5之后,我遇到了一些错误,这些错误表明我要替换cccolor4f,glpushmatrix等。但我无法找到glscalef函数的替代方案。我在这个函数调用时遇到错误。
这是我的代码:
[super draw];
kmGLPushMatrix();
{
// No idea what will replace this one
// glScalef(PTM_RATIO, PTM_RATIO,0.f);
ccDrawColor4F(0.f, 1.f, 0.f, 1.f);
[physicsshapeobject debugdraw]; // This calls the function below for different shapes
}
kmGLPopMatrix();
ccDrawColor4F(1.f, 1.f, 0.f, 1.f);
ccPointSize(10.f);
//drawPoint(collisionAt_);
ccPointSize(1.f);
}
-(void) debugDraw{
if(polygonShape != NULL){
CGPoint boxPt = ccpFromB2Vec(shapeTransform->p, NO);
CGPoint p1 = ccpAdd(boxPt,ccpFromB2Vec(polygonShape->m_vertices[0], NO));
CGPoint p2 = ccpAdd(boxPt,ccpFromB2Vec(polygonShape->m_vertices[1], NO));
CGPoint p3 = ccpAdd(boxPt,ccpFromB2Vec(polygonShape->m_vertices[2], NO));
CGPoint p4 = ccpAdd(boxPt,ccpFromB2Vec(polygonShape->m_vertices[3], NO));
ccVertex2F v1;
ccVertex2F v2;
ccVertex2F v3;
ccVertex2F v4;
v1.x = p1.x;
v1.y = p1.y;
v2.x = p2.x;
v2.y = p2.y;
v3.x = p3.x;
v3.y = p3.y;
v4.x = p4.x;
v4.y = p4.y;
ccQuad2 quad = (ccQuad2){
v1,
v2,
v3,
v4,
};
ccDrawColor4F(1.f, 0.f, 0.f, 1.f);
ccDrawPoly((CGPoint*)&quad, 4, YES);
}
}
形状不画的原因是什么? cocos2d 2.0中glscalef的替代方法是什么?
感谢任何帮助!
由于
答案 0 :(得分:1)
现在Cocos2D 3.0与Chipmunk2D物理引擎深度集成。因此,如果您使用默认的CCPhysicsNode
,则可以通过简单地调用setDebugDraw
来启用调试绘图:
_physicsWorld = [CCPhysicsNode node];
_physicsWorld.gravity = ccp(0,0);
_physicsWorld.debugDraw = YES;
_physicsWorld.collisionDelegate = self;
[self addChild:_physicsWorld];