国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

cocos2dx,Layer錨點(diǎn)與scale縮放

2019-11-14 18:22:39
字體:
供稿:網(wǎng)友

最近寫代碼需要用到縮放,而且是Layer的,但是發(fā)現(xiàn)怎么設(shè)置位置都是錯(cuò)誤,于是決定研究下。

首先,基礎(chǔ)代碼,代碼上不錯(cuò)特殊處理,沒有錨點(diǎn)設(shè)置和縮放

class TestLayer : public Layer {    public:        bool init();    CREATE_FUNC(TestLayer);};bool TestLayer::init(){    if (!Layer::init()) {        return false;    }        SPRite *dd = Sprite::create("item_gift1.png");    this->addChild(dd);        this->setContentSize(Size(200, 200));        // 打印幾個(gè)點(diǎn)參照用    LayerColor *lc1 = LayerColor::create(Color4B::RED, 10, 10);    lc1->setPosition(50, 0);    this->addChild(lc1, 9001);        LayerColor *lc4 = LayerColor::create(Color4B::RED, 10, 10);    lc4->setPosition(100, 0);    this->addChild(lc4, 9001);        LayerColor *lc2 = LayerColor::create(Color4B::RED, 10, 10);    lc2->setPosition(150, 0);    this->addChild(lc2, 9001);        LayerColor *lc6 = LayerColor::create(Color4B::RED, 10, 10);    lc6->setPosition(200, 0);    this->addChild(lc6, 9001);        LayerColor *lc3 = LayerColor::create(Color4B::RED, 10, 10);    lc3->setPosition(0, 50);    this->addChild(lc3, 9001);        LayerColor *lc5 = LayerColor::create(Color4B::RED, 10, 10);    lc5->setPosition(0, 100);    this->addChild(lc5, 9001);        LayerColor *lc7 = LayerColor::create(Color4B::RED, 10, 10);    lc7->setPosition(0, 150);    this->addChild(lc7, 9001);        LayerColor *lc8 = LayerColor::create(Color4B::RED, 10, 10);    lc8->setPosition(0, 200);    this->addChild(lc8, 9001);        return true;}

 

    TestLayer *t = TestLayer::create();    t->setPosition(200, 200);    this->addChild(t, 9000);

 代碼運(yùn)行結(jié)果:

可以看到,TestLayer被放置在了(200,200),錨點(diǎn)在(0,0)

下面對TestLayer進(jìn)行縮放0.5

TestLayer *t = TestLayer::create();t->setPosition(200, 200);t->setScale(0.5f);

 運(yùn)行結(jié)果:

(黃線是截圖時(shí)畫的)

可以看到TestLayer縮放了50%,但是左下角沒有在(200,200)

通過這個(gè)代碼可以看出,Layer中的child是以(0,0)為錨點(diǎn),但是在scale時(shí),確實(shí)以(0.5,0.5)進(jìn)行縮放。

這個(gè)地方感覺比較坑,為什么沒有用統(tǒng)一的點(diǎn)呢?沒有寫過底層畫圖代碼,哪位同學(xué)知道,希望給我一個(gè)答案。

那這個(gè)地方可不可以統(tǒng)一呢?

看代碼:

this->_ignoreAnchorPointForPosition = false;this->setAnchorPoint(Point(0, 0));

 在TestLayer中增加上面代碼,運(yùn)行結(jié)果:

 

可以看到縮放和child位置錨點(diǎn)一致了。

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 湘阴县| 平原县| 民和| 沁阳市| 伊吾县| 威海市| 公主岭市| 兰西县| 双柏县| 文成县| 新沂市| 城步| 安龙县| 通榆县| 来凤县| 鄂托克旗| 丰顺县| 阳江市| 镇赉县| 拉萨市| 三河市| 敖汉旗| 东宁县| 宁都县| 财经| 桐庐县| 江西省| 浦江县| 鄢陵县| 柯坪县| 会昌县| 高唐县| 巴林左旗| 剑河县| 晋宁县| 宁城县| 浠水县| 班玛县| 康乐县| 仙游县| 武定县|