开发者

cocos2d, how to make b2World draw my own data?

开发者 https://www.devze.com 2023-03-19 09:45 出处:网络
I am working on a Box2d Edit开发者_运维技巧or for iOS, using cocos2d. I wrapped b2World into my own World class. I want to implement my own draw functionality. Since I will be drawing higher level cl

I am working on a Box2d Edit开发者_运维技巧or for iOS, using cocos2d.

I wrapped b2World into my own World class. I want to implement my own draw functionality. Since I will be drawing higher level classes (Wall, Rope, etc) it is not enough to create a b2Draw subclass and set it as DebugDraw of the world, but I also need to change the b2World DrawDebugData.

Is it a good idea to inherit my World class from CCLayer and override the draw method? Whats a better approach?


Just add CCSprite pointer into b2Body userData to attach a sprite to b2Body. Then every frame update your sprites position according to position of b2bodies.


The answer I would like people to read.

Even if the b2World implements some drawing functionality, it is just meant for debugging purposes and should be used as it is (unless you want to change one or two lines).

If you want to draw your higher level objects (or to change debug draw's behaviour) you are not supposed to modify b2World's draw or the GLES-Render. Instead, you override CCSprite / CCLayer drawing methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号