Hey there, I’m adding away3D as 3d view into my game engine rules by 2D physics (box2d & Nape).
I’ve created a wrapper for the box2d debug view :
package com.citrusengine.view.away3dview {
import com.citrusengine.core.State;
import away3d.Away3D;
import away3d.containers.ObjectContainer3D;
import Box2DAS.Dynamics.b2DebugDraw;
import com.citrusengine.core.CitrusEngine;
import com.citrusengine.physics.Box2D;
import com.citrusengine.view.away3dview.Away3DArt;
import flash.events.Event;
/**
* @author Aymeric
*/
public class Box2DDebugArt extends ObjectContainer3D {
private var _box2D:Box2D;
private var _debugDrawer:b2DebugDraw;
public function Box2DDebugArt() {
addEventListener(Event.ADDED, handleAddedToParent);
addEventListener(Event.ENTER_FRAME, handleEnterFrame);
addEventListener(Event.REMOVED, destroy);
trace('created');
}
private function handleAddedToParent(evt:Event):void {
trace('added');
removeEventListener(Event.ADDED, handleAddedToParent);
if (parent is Away3DArt)
_box2D = Away3DArt(parent).citrusObject as Box2D;
else
_box2D = CitrusEngine.getInstance().state.getFirstObjectByType(Box2D) as Box2D;
_debugDrawer = new b2DebugDraw();
(CitrusEngine.getInstance().state as State).addChild(_debugDrawer);
_debugDrawer.world = _box2D.world;
_debugDrawer.scale = _box2D.scale;
}
private function destroy(e:Event):void
{
removeEventListener(Event.ADDED, handleAddedToParent);
removeEventListener(Event.ENTER_FRAME, handleEnterFrame);
removeEventListener(Event.REMOVED, destroy);
}
private function handleEnterFrame(evt:Event):void
{trace('ef');
_debugDrawer.Draw();
}
}
}
However the different listeners are never called! This is strange for a container class. I found the issue reported there. If it can’t be added,what is the workaround ?
Thanks for the help!