EventDispatcher (r58) [英] EventDispatcher (r58)

查看:34
本文介绍了EventDispatcher (r58)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于 r58 中的 EventDispatcer 发生了一些变化,我无法向对象添加更多自定义事件.根据 将自定义事件添加到 Object3D 我曾经拥有:

Something changed in regards to the EventDispatcer in r58 and I cannot add any more custom events to Objects. As per Add custom event to Object3D I used to have:

var spinner_obj = new THREE.Object3D();
THREE.EventDispatcher.call( spinner_obj );
spinner_obj.addEventListener('start', function(event) {alert("GOT THE EVENT");});
spinner_obj.dispatchEvent({type:'start'});

但这在 r58 中停止工作并显示错误消息:

but this stopped working in r58 with the error message:

Object [object Object] has no method 'addEventListener' 

推荐答案

现在它使用函数的单个实例,而不是在每个对象中复制它.

Now it's using a single instance of the functions instead of duplicating it in every object.

这是我目前找到的最好的方法:https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/OBJLoader.js#L11-L14

This is the best approach I've found so far: https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/OBJLoader.js#L11-L14

我想我会让 Object3D 扩展 EventDispatcher 原型...

I think I'll make Object3D extend EventDispatcher prototype though...

这篇关于EventDispatcher (r58)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆