简体   繁体   English

Tween.js在添加EventListener之后未调用调用函数

[英]Tween.js not callling call function after adding EventListener

I am using tween.0.6.2 and ran into a problem. 我正在使用tween.0.6.2并遇到问题。

Follwing code snippet (taken from the tween.js Getting Started site and slightly simplified) works just like it should: 以下代码段(取自tween.js入门网站 ,略有简化)的工作原理如下:

            createjs.Tween.get(circle)
                .to({x: 400}, 1000, createjs.Ease.getPowInOut(4))
                .call(function() {console.log("tween finished");});

After the tween has been finished (the circle has been moved to x=400) the function passed to call is executed. 补间完成后(圆已移动到x = 400),将执行传递给call的函数。

But after an event handler was added like so: 但是在添加事件处理程序之后,像这样:

            createjs.Tween.get(circle)
                .to({x: 400}, 1000, createjs.Ease.getPowInOut(4))
                .addEventListener("change", function() {console.log("tween changed");} )
                .call(function() {console.log("tween finished");});

the function passed to call is not executed anymore. 传递给call的函数不再执行。

Any ideas ? 有任何想法吗 ?

For everyone stumbling over this: after some experimenting, I found out that this works: 对于每个绊脚的人:经过一些试验,我发现这可行:

           createjs.Tween.get(circle)
                .to({x: 400}, 1000, createjs.Ease.getPowInOut(4))
                .call(function() {console.log("tween finished");})
                .addEventListener("change", function() {console.log("tween changed");} )

As it seems, the call to call must precede the call to addEventListener . 看起来,对call的call必须在对addEventListener的调用之前。

EDIT: 编辑:

Still not working the way it is expected to: in the above example, the event listener gets called one more time after(!) the function passed to call is executed. 仍然无法按预期的方式工作:在上面的示例中,在传递给call的函数执行(!)之后,事件监听器又被调用了一次。

Ideas as to why this is happening are still welcome ... 关于这种情况为什么发生的想法仍然受到欢迎...

addEventListener is not tween-js function. addEventListener不是tween-js函数。 All chained functions like to and call assuming to return this object (instance of Tween) and addEventListener returns undefined . 所有链接的函数(如tocall假定要返回this对象(Tween的实例),而addEventListener返回undefined So, last call() will called upon undefined . 因此,最后一个call()将调用undefined

You must use onUpdate instead of addEventListener : 您必须使用onUpdate而不是addEventListener

         createjs.Tween.get(circle)
                .to({x: 400}, 1000, createjs.Ease.getPowInOut(4))
                .onUpdate(function() {console.log("tween changed");} )
                .call(function() {console.log("tween finished");});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM