如何在Three.js中的对象方法调用上调度事件?

时间:2018-12-13 15:08:12

标签: three.js

我试图在这样的方法调用上调度事件:

"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-router-redux": "^4.0.8",
"redux": "^4.0.0",
"redux-thunk": "^2.3.0"

并在画布上听,就像这样:

Group.remove(obj).dispatchEvent({type:'remove', message:'Object removed'});

但是什么也没发生... 在Three.js Object3D的页面上说Three.js EventDispatcher方法可用。那么我在做什么错了?

r98

1 个答案:

答案 0 :(得分:4)

THREE.EventDispatcher与DOM事件无关。它仅在自定义JavaScript对象上启用事件驱动的API。来自github repository的以下示例可能有助于更好地理解这一点:

function Car() {

    this.start = function () {

        this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );

    };

}

Object.assign( Car.prototype, EventDispatcher.prototype );

// Using events

var car = new Car();

car.addEventListener( 'start', function ( event ) {

    alert( event.message );

} );

car.start();

three.js R99