CCScene,CCLayer,CCSprite的默认坐标和默认锚点

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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值