Cocos2dx,layer anchor Point and scale scaling

Source: Internet
Author: User
Tags addchild

The most recent writing code needs to be scaled, and it's layer, but it's a matter of finding out how to set the location, so I decided to study it.

First, the base code, the code good special handling, no anchor settings and scaling

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));    Print several point references with 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 (a);    This->addchild (t, 9000);

Code Run Result:

As can be seen, Testlayer is placed in (200,200), Anchor Point in (0,0)

The Testlayer is scaled below 0.5

Testlayer *t = Testlayer::create (); T->setposition (n.); T->setscale (0.5f);

Operation Result:

(The Yellow Line is painted at the time)

You can see that the testlayer is scaled by 50%, but the lower left corner is not in (200,200)

As you can see from this code, the child in the layer is anchored (0,0), but at scale it is indeed scaled (0.5,0.5).

This place feels like a pit, why not use a uniform point? Did not write the underlying drawing code, which students know, hope to give me an answer.

Could this place be unified?

Look at the code:

This->_ignoreanchorpointforposition = False;this->setanchorpoint (Point (0, 0));

Add the above code to the Testlayer and run the result:

You can see that the zoom is consistent with the child position anchor point.

Cocos2dx,layer anchor Point and scale scaling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.