bool HelloWorld::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(! CCLayer::init());
CCSprite * sprite = CCSprite::create("image1.png");
this->addChild(sprite);
//获得CCSprite的默认坐标
CCLog("CCSprite.x=%f,CCSprite.y=%f",sprite->getPosition().x,sprite->getPosition().y);
//获得CCSprite的默认锚点
CCLog("sprite1Anchor.x=%f,sprite1Anchor.y=%f",sprite->getAnchorPoint().x,sprite->getAnchorPoint().y);
//获得CCLayer的默认坐标
CCLog("CCLayer.x=%f,CCLayer.y=%f",this->getPosition().x,this->getPosition().y);
//获得CCLayer的默认锚点
CCPoint point = this->getAnchorPoint();
CCLog("layerAnchor.x=%f,layerAnchor.y=%f",point.x,point.y);
bRet = true;
} while (0);
return bRet;
}
CCScene* HelloWorld::scene()
{
CCScene * scene = NULL;
do
{
// 'scene' is an autorelease object
scene = CCScene::create();
CC_BREAK_IF(! scene);
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
CC_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
layer->show();
} while (0);
// return the scene
return scene;
}
void HelloWorld::show()
{
//获得CCScene的默认坐标
CCScene * scene = (CCScene *)this->getParent();
CCLog("CCScene.x=%f,CCScene.y=%f",scene->getPosition().x,scene->getPosition().y);
//获得CCScene的默认锚点
CCPoint point = scene->getAnchorPoint();
CCLog("SceneAnchor.x=%f,SceneAnchor.y=%f",point.x,point.y);
}
实践证明这三个东西的默认坐标都是0,0 默认锚点都是0.5,0.5