码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d中锚点概念

时间:2015-03-10 11:53:40      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

  这两天看了下锚点的概念。

 

    /**

     * Sets the anchor point in percent.

     *

     * anchorPoint is the point around which all transformations and positioning manipulations take place.

     * It‘s like a pin in the node where it is "attached" to its parent.

     * The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.

     * But you can use values higher than (1,1) and lower than (0,0) too.

     * The default anchorPoint is (0.5,0.5), so it starts in the center of the node.

     *

     * @param anchorPoint   The anchor point of node.

     */

    virtual void setAnchorPoint(const CCPoint& anchorPoint);

 

 

 

anchorPoint is the point around which all transformations and positioning manipulations take place.

是为了在定位位置和翻转的时候用的参考点。

    CCSprite* sprite5 = CCSprite::create("CloseNormal.png");

    sprite5->setAnchorPoint( ccp(0.5,0.5) );

    sprite5->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

    this->addChild(sprite5);

 

此时 (ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2)) 点正在sprite5的中心点( ccp(0.5,0.5))

 

 

 

  CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();

    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

 

    // 右上角

    CCSprite* sprite1 = CCSprite::create("CloseSelected1.png");

    sprite1->setAnchorPoint( ccp(0,0) );

    sprite1->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

    this->addChild(sprite1);

    

    

    // 左上角

    CCSprite* sprite2 = CCSprite::create("CloseNormal.png");

    sprite2->setAnchorPoint( ccp(1,0) );

    sprite2->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

    this->addChild(sprite2);

    

    // 左下角

    CCSprite* sprite3 = CCSprite::create("CloseNormal.png");

    sprite3->setAnchorPoint( ccp(1,1) );

    sprite3->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

    this->addChild(sprite3);

 

    // 右下角

    CCSprite* sprite4 = CCSprite::create("CloseNormal.png");

    sprite4->setAnchorPoint( ccp(0,1) );

    sprite4->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

    this->addChild(sprite4);

 

    // 中间

    CCSprite* sprite5 = CCSprite::create("CloseNormal.png");

    sprite5->setAnchorPoint( ccp(0.5,0.5) );

    sprite5->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

    this->addChild(sprite5);

 

 

技术分享

 

cocos2d中锚点概念

标签:

原文地址:http://www.cnblogs.com/lpwlpw/p/4325288.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!