我最终设法使我的程序检测到我用Java-3D创建的两个球之间的碰撞;玩家球和敌人球。现在的问题是,我不知道如何在玩家球与敌方球碰撞时将其移走。我尝试过一些简单的操作,例如objTrans.removeChild(sphere);
和objRoot.removeChild(objTrans);
(objTrans是我的TransformGroup,而objRoot是我的BranchGroup),在两种情况下,我都会收到此错误消息
Exception in thread "AWT-EventQueue-0" javax.media.j3d.RestrictedAccessException: Group: only a BranchGroup node may be removed
我也尝试过objRoot.detach();
,但随后收到错误消息:
Exception in thread "AWT-EventQueue-0" javax.media.j3d.CapabilityNotSetException: BranchGroup: no capability to detach
我不知道有什么其他方法可以去除球。请帮助。
private BranchGroup mapGroup = null;
public void updateModel (....)
{
Shape3D shape;
// Update 3D primitives
if (mapGroup != null) // remove previous 3D model
object.removeChild (mapGroup);
shape = facesTexturedShape (....);
if (shape != null) // add new 3D model if non-null
{
mapGroup = new BranchGroup ();
mapGroup.setCapability (BranchGroup.ALLOW_DETACH);
mapGroup.addChild (shape);
object.addChild (mapGroup);
}
}