将自定义事件添加到 Object3D [英] Add custom event to Object3D

查看:37
本文介绍了将自定义事件添加到 Object3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Object3D 节点构建场景图.我想将几个节点视为 Spin 对象,它们从一开始就没有活动,但是当它们收到特定的开始"事件时就会变为活动状态,可能使用计时器来启动它.我需要一些帮助来设置它.我试过下面的代码

I am building a scenegraph out of Object3D nodes. Several of the nodes I would like to treat as Spin objects that are not active since the beginning but they become active when they receive a specific 'start' event, probably using a timer to fire it up. I need some assistance in setting this up. I have tried the following code

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

但这给了我一个错误TypeError: spinner_obj.addEventListener is not a function"

but this gives me an error "TypeError: spinner_obj.addEventListener is not a function"

此外,我还需要做什么才能触发这个开始"事件?我是 javascript 初学者.我曾尝试关注 https://github.com/mrdoob/eventdispatcher.js 但我需要一些更多的指针.谢谢.

In addition what would I have to do to fire this 'start' event? I am a javascript beginner. I have tried to follow https://github.com/mrdoob/eventdispatcher.js but I need some more pointers. Thank you.

推荐答案

尝试这样做:

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'});

这篇关于将自定义事件添加到 Object3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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