axmolengine / axmol

Axmol Engine – A Multi-platform Engine for Desktop, XBOX (UWP) and Mobile games. (A fork of Cocos2d-x-4.0)
https://axmol.dev
MIT License
922 stars 205 forks source link

consider new render vertex Coord in axmol ver2 #1458

Closed antn9x closed 11 months ago

antn9x commented 11 months ago

I found a fix! go to the engine's code in CCSprite.cpp and make this change to the function setVertexCoords:

image

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:

image image

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

antn9x commented 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.

rh101 commented 11 months ago

@antn9x Sorry, I don't understand what you mean. A fix for what exactly?

antn9x commented 11 months ago

I mean "default render child node at center of parent node" for all Node type without set Anchor point = Vec2(0.5, 0.5)

rh101 commented 11 months ago

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.

antn9x commented 11 months ago

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.

aismann commented 11 months ago

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()));

image

btw: @antn9x You screenshot looks a little bit crazy for me.

aismann commented 11 months ago

@antn9x Can you close this issue plz?