Change Box2D Anchor Point?

拟墨画扇 提交于 2019-12-23 03:50:19

问题


In Cocos2D I am creating my CCSprites with anchor points of (0,1) which is similar to the way UIKit does it. Anyway, I am trying to change the anchor point in Box2D, is this possible? If so how would I do it with an anchor point of (0,1)?

Thanks!


回答1:


Box2D bodies don't have an anchor point.

The anchorPoint is an offset of a node's texture relative to the node's position. Box2D bodies don't have a texture, hence no anchor point.

Generally speaking you're going to make a lot of things more difficult by changing the anchorPoint from its default 0.5,0.5 position. Like, for example, the issue that lead you to ask this very question.




回答2:


Changing anchor point of shapes in body :

do a for loop to get the smallest x vertice and the biggest, substract to get the width, you can do in the same loop get smallest y vertice and the biggest and substract,

if you then move all vertices with the differences you will position the shape in the 0,0.

it works not sure if the best solution.



来源:https://stackoverflow.com/questions/8025576/change-box2d-anchor-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!