cocos2d,如何让b2World绘制我自己的数据?
我正在使用 cocos2d 开发适用于 iOS 的 Box2d 编辑器。
我将 b2World
包装到我自己的 World 类中。我想实现我自己的绘图功能。由于我将绘制更高级别的类(墙、绳索等),因此创建 b2Draw
子类并将其设置为世界的 DebugDraw 是不够的,但我还需要更改 b2World
DrawDebugData
。
从 CCLayer
继承我的 World 类并重写 draw
方法是个好主意吗?有什么更好的方法?
I am working on a Box2d Editor 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将 CCSprite 指针添加到
b2Body
userData 中即可将精灵附加到 b2Body。然后每一帧根据 b2body 的位置更新精灵位置。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.我希望人们阅读的答案。
即使 b2World 实现了一些绘图功能,它也只是用于调试目的,应该按原样使用(除非您想更改一两行) 。
如果您想绘制更高级别的对象(或更改调试绘制的行为),则不应修改 b2World 的绘制或 GLES-Render。相反,您可以重写 CCSprite / CCLayer 绘图方法。
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.