Away3d网格没有得到mouseClick事件

时间:2014-07-17 03:49:51

标签: actionscript-3 starling-framework away3d mouse-picking

我只是想在一个平面上获取鼠标的坐标,但鼠标事件不会发射。

我在off3d上面还有一个starling实例,我跟this tutorial有关,我相信那里有一个问题。 这是我的代码:

public class Main extends Sprite
{

    private var view3D:View3D;
    private var stage3DManager:Stage3DManager;
    private var stage3DProxy:Stage3DProxy;

    public function Main():void
    {
        if (stage)
            init();
        else
            addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point

        view3D = new View3D();

        initProxies();
    }

    private function initProxies():void
    {
        stage3DManager = Stage3DManager.getInstance(stage);

        stage3DProxy = stage3DManager.getFreeStage3DProxy();
        stage3DProxy.addEventListener(Stage3DEvent.CONTEXT3D_CREATED, onContextCreated);
    }

    private function onContextCreated(event:Stage3DEvent):void
    {
        initAway3D();
        initStarling();

        var floor:Mesh = new Mesh(new PlaneGeometry(600, 400), new ColorMaterial(0x530000));
        floor.mouseEnabled = true;
        view3D.scene.addChild(floor);

        addEventListener(Event.ENTER_FRAME, onEnterFrame);
        floor.addEventListener(MouseEvent3D.CLICK, onClick);

    }

    private function onClick(e:MouseEvent3D):void
    {
        trace("Click");
    }

    private function initAway3D():void
    {

        view3D.stage3DProxy = stage3DProxy;
        view3D.shareContext = true;

        addChild(view3D);

        view3D.mousePicker = PickingType.SHADER;

        view3D.camera = new Camera3D(new OrthographicLens());
        view3D.camera.x = 1000;
        view3D.camera.y = 1000;
        view3D.camera.z = 1000;
        view3D.camera.lookAt(new Vector3D(0, 0, 0));
    }

    private function initStarling():void
    {
        var starling:Starling = new Starling(StarlingSprite, stage, stage3DProxy.viewPort, stage3DProxy.stage3D);
        starling.showStats = true;
        starling.start();
    }

    private function onEnterFrame(e:Event):void
    {
        stage3DProxy.clear();

        view3D.render();

        stage3DProxy.present();
    }

}

}

1 个答案:

答案 0 :(得分:0)

我正在开发一个小项目,我从本教程开始,一切正常! 我有羽毛问题,但是当我打电话给starling.start()时我解决了这个问题,但是你已经做过了,但是你已经做过了。)

试试这个:

private function initStarling():void
{
    starling = new Starling(StarlingSprite, stage, stage3DProxy.viewPort, stage3DProxy.stage3D);
    starling.addEventListener(Event.ROOT_CREATED, rootCreatedHandler);
}

private function rootCreatedHandler(event:Event):void
{
    starling.removeEventListener(Event.ROOT_CREATED, rootCreatedHandler);

    stage3DProxy.addEventListener(flash.events.Event.ENTER_FRAME, onEnterFrame);

    starling.start();
}

private function onEnterFrame(event:flash.events.Event):void
{
    view3D.render();

    starling.nextFrame();
}

我希望它能帮到你!