问题
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