bool GameScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
auto rootNode = CSLoader::createNode(“GameScene.csb”);
addChild(rootNode);
Size visibleSize = Director::getInstance()->getVisibleSize();
auto boxNode = Sprite::create();
auto boxBody = PhysicsBody::createEdgeBox(visibleSize, PHYSICSBODY_MATERIAL_DEFAULT, 3.0f);
boxNode->setPhysicsBody(boxBody);
boxNode->setPosition(visibleSize/2);
this->addChild(boxNode);
CCSpriteFrameCache::getInstance()->addSpriteFramesWithFile(“GameScene/GameScene.plist”);
auto ball = Sprite::createWithSpriteFrameName(“GameScene/Ball.png”);
auto ballBody = PhysicsBody::createCircle(ball->getContentSize().width/2);
ball->setPhysicsBody(ballBody);
ball->setPosition(Vec2(320, 100));
this->addChild(ball);
log(".2f, .2f", ball->getPositionX(), ball->getPositionY());
log(".2f, .2f", ball->getContentSize().width, ball->getContentSize().height);
auto paddle = Sprite::createWithSpriteFrameName(“GameScene/Paddle.png”);
paddle->setPosition(Vec2(320, 75));
this->addChild(paddle);
为什么设置这块代码之后 在ios模拟器上 球体有时候会显示 有时候会不显示呢?
