javascript - 未捕获的类型错误:this._tweens[i].update 不是 Phaser.TweenManager.update 中的函数
问题描述
我正在使用移相器 2.3.0。我陷入了困境。我使用以下代码一次在多个精灵上应用补间:-
var GameState = {
create:function(){
------
this.circle1;
this.time.events.loop(Phaser.Timer.SECOND * 2, this.updateCirclePosition, this);
------
},
updateCirclePosition:function(){
this.circle1 = this.add.sprite(30,40,'circle1')
this.tweenCircle1 = this.tweens.add({
targets: [this.circle1], // or targets: this.circle1
y: '+=50',
duration: 400,
ease: 'Linear'
});
}
}
但它不起作用。它只创建精灵图像,但没有在其上应用任何补间,并且在创建精灵之后它显示以下错误消息phaser.js:47296 Uncaught TypeError: this._tweens[i].update is not a function
at Phaser.TweenManager.update
。当我应用以下代码时,它工作正常
this.tweenCircle1 = this.add.tween(this.circle1)
this.tweenCircle1.to({y:90},400);
this.tweenCircle1.start();
上面代码中的问题是什么不起作用
解决方案
this.tweenCircle1 = this.tweens.add({
targets: [this.circle1], // or targets: this.circle1
y: '+=50',
duration: 400,
ease: 'Linear'
});
是 Phaser 3 的代码
如果你想使用 Phaser 2 CE,代码看起来像这样
this.add.tween(this.circle1).to({ y: '+50' }, 400, 'Linear', true)
Tween.to 参数如下:
to(properties [, duration] [, ease] [, autoStart] [, delay] [, repeat] [, yoyo])
推荐阅读
- laravel - Laravel 与枢轴同步多对多关系
- c# - 为什么在尝试获取已登录用户的用户名以便我可以在共享的 LayoutView 中显示它时出现此错误
- javascript - response.json() 中的值计数来自哪里?
- swift - 使用 GeometryReader 调整窗口大小时在 SwiftUI 中调整矩形网格的大小
- bash - 如何通过 CGI 脚本运行 jar 文件
- authentication - 使用 AuthenticationManager.GetWebLoginClientContext 对用户进行身份验证后,是否可以确定用户的登录名?
- javascript - 我正在尝试在 javascript 生成的 html 中生成一个 onclick 方法,它给了我一些非常奇怪的结果
- c++ - 值未显示,并遇到异常。是什么赋予了?
- c# - Kestrel 服务器声称在端口中侦听,但它没有
- python - 似乎无法在 Python 中交换记录数组中的行