Closed antn9x closed 11 months ago
@rh101 @DelinWorks Can we have render vertex Coord like other game engine in axmol v2? They will default render child node at center of parent node.
@antn9x Sorry, I don't understand what you mean. A fix for what exactly?
I mean "default render child node at center of parent node" for all Node type without set Anchor point = Vec2(0.5, 0.5)
I mean "default render child node at center of parent node" for all Node type without set Anchor point = Vec2(0.5, 0.5)
What does setAnchorPoint
have to do with centering it in the parent? setAnchorPoint
only affects the node that it is applied to, and setPosition
is what positions the node within the parent.
What you're effectively trying to do is set the 0,0
coordinate to be in the center of a node, rather than the bottom left that this engine uses. This is not a bug, but a design choice, so stating that you have "found a fix" is a little misleading. A change like what you suggest affects many parts of the engine, and any projects using it.
In addition to that, if other engines have 0,0 as the middle coordinate of a node, then that does not mean every engine needs to implement it that way.
There are some advantage of render child node at center while design scene, maybe some old projects will be not supported but we can have new version to support new render.
Sorry, look there that the correct source for center a Node into another Node e.g. Sprite:
// add the label as a child to this Node (e.g. Sprite)
sprite->addChild(label, 1);
// position the label on the center of the sprite
label->setPosition(Vec2(sprite->getCenterRect().getMidX(), sprite->getCenterRect().getMidY()));
btw: @antn9x You screenshot looks a little bit crazy for me.
@antn9x Can you close this issue plz?
I found a fix! go to the engine's code in
CCSprite.cpp
and make this change to the functionsetVertexCoords
:This should be the right way to shift a sprite to the center, not with
setAnchorPoint
You can see now that the label appears in the center of the sprite:of course, the letters in the label are misplaced because we modified the engine's code directly and the code applies to everything renderable so I think a pull request that adds a separate function should fix this.
Originally posted by @DelinWorks in https://github.com/axmolengine/axmol/discussions/998#discussioncomment-4548220