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!");
}