box2d b2DestructionListener注意事项

b2DesctructionListener只会对隐式销毁的 fixture 和 b2Joint 做响应

也就是说:

如果你在销毁一个 body 的时后,body上面的 fixture 和 joint 你未曾事先销毁掉,

那么,这些 fixture 和 joint 就会在 b2DesctructionListener 的回调方法里面得以体现;

如果一个body包含了多个 fixture,你仅仅只是销毁了 body 里面的某一个 fixture,

那么这个 fixture 是由你自主来进行销毁的,不会在b2DesctructionListener 的回调方法里面得以体现。


一言以蔽之,只有 box2d 帮你销毁的 fixture 和 joint,才会在 回调中得以体现,

而你自己调用 DestroyFixture() 和 DestroyJoint() 方法来销毁的,则不会。


因为没经过测试,我有一个疑问:

b2RopeJoint 并非继承自 b2Joint ,会否在隐式销毁的过程中在回调中有所表现?

如今事情比较忙,只有待以后有机会有时间再去测试了。


发一份 b2DesctructionListener 用例代码:

MyDestructionListener.h

// // MyDestructionListener.h // GameSceneEx // // Created by Bruce Yang on 12-4-22. // Copyright (c) 2012年 EricGameStudio. All rights reserved. // #ifndef GameSceneEx_MyDestructionListener_h #define GameSceneEx_MyDestructionListener_h #include "Box2D.h" class MyDestructionListener : public b2DestructionListener { public: MyDestructionListener(); ~MyDestructionListener(); /// Called when any joint is about to be destroyed due /// to the destruction of one of its attached bodies. virtual void SayGoodbye(b2Joint* joint); /// Called when any fixture is about to be destroyed due /// to the destruction of its parent body. virtual void SayGoodbye(b2Fixture* fixture); }; #endif MyDestructionListener.mm
// // MyDestructionListener.cpp // GameSceneEx // // Created by Bruce Yang on 12-4-22. // Copyright (c) 2012年 EricGameStudio. All rights reserved. // #include "MyDestructionListener.h" MyDestructionListener::MyDestructionListener() { } MyDestructionListener::~MyDestructionListener() { } void MyDestructionListener::SayGoodbye(b2Joint* joint) { NSLog(@"joint be destroyed!"); } void MyDestructionListener::SayGoodbye(b2Fixture* fixture) { NSLog(@"fixture be destroyed!"); }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值