Cocos2dx b2body.def 如何设置坐标


大家好,
刚学android,做个小程序需要用到cocos2dx的引擎,在极客学院上学flappy bird的课程,现在问题是不管是自己写的代码还是直接下载的代码,编译后在屏幕上都看不见图像,只有黑色的背景,代码如下


 void FlappyBird::addBird()
{ 
bird = B2Sprite::create("bird.png");
CCSize size = bird->getContentSize();

b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position = b2Vec2(screenSize.width/2/RATIO, 9);
//bodyDef.position = b2Vec2(0.0f, 5.0f);
b2Body *birdBody = world->CreateBody(&bodyDef);

b2PolygonShape birdShape;
birdShape.SetAsBox(size.width/2/RATIO, size.height/2/RATIO);

b2FixtureDef birdFixtureDef;
birdFixtureDef.shape = &birdShape;
birdBody->CreateFixture(&birdFixtureDef);

bird->setPTMRatio(RATIO);
bird->setB2Body(birdBody);
addChild(bird);
}

屏幕大小设置为480*320,RATIO=48,将b2vec2改称(0.0f,5.0f)也不对,大家知道哪里错了吗?

教程链接: http://www.jikexueyuan.com/course/show/id/34.html

cocos2d-x Android

东方八云紫 10 years, 11 months ago

Your Answer