* *********************************** Please specify the source: bytes ********************************************
Over the past few days, I have been playing 2048 games (out of stock)
You need to set a grid layer in one scenario,
However, the anchor is not set correctly. Therefore, you can search for the anchor through the Internet + practice = discover:
By default, the anchpoint of the original layer and scene cannot be changed.
Solution:
Call a function in node:
ignoreAnchorPointForPosition(bool)
Take a look at the API:
Well, if there are some obstacles to English, well... Here are the APIs in the Chinese version 3.0 (for more information, see the English version ):
The default value is true.
You only need to change this value to false to change the position of the anchor.
For example:
Auto colorbox = layercolor: Create (color4b (170,170,170,255); colorbox-> ignoreanchorpointforposition (false); colorbox-> setanchorpoint (point (0.5, 0.5 )); colorbox-> setposition (point (Coordinate Position); this-> addchild (colorbox );
How can I determine where the anchor is set?
Convert the image into a small grid of 1x1,
Lower left corner of 0, 0
1. top right corner
Bottom right corner
0, 1 upper left corner
0.5 0.5 Central
Node also provides the isignoreanchorpointforposition method,
To determine whether the anchor of the layer or scene can be changed.
Of course, this method (ignoreanchorpointforposition)
You can also set the object anchor of Sprite to 0, 0, and cannot change it.
For example:
auto sprite = Sprite::create("HelloWorld.png");sprite->ignoreAnchorPointForPosition(true);sprite->setAnchorPoint(Point(1,0));sprite->setPosition(Point(GAME_SCREEN_WIDTH/2,GAME_SCREEN_HEIGHT/2));this->addChild(sprite, 0);
In fact, setting the anchor is useless,
However, if you change ignoreanchorpointforposition to false,
You can change the position of the anchor.
Maybe, you will ask: what is the use of setting the sprite anchor to be fixed to 0 or 0?
Me: I don't know either... I can only find this method. What can I do? Check your idea ~
Note:
-- If it is set to true, it indicates that the default 0, 0 of the anchor cannot be changed,
-- If it is set to false, it indicates that the anchor can be changed,
Therefore, this method cannot be used to set an object's anchor. You cannot change this anchor.
As long as the anchor cannot be changed, the anchor can only be 0, 0 (lower left corner )!
* *********************************** Please specify the source: bytes ********************************************
About cocos2d-x 3.x layer and scene anchor changes