首页 > 解决方案 > 未捕获的类型错误: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();

上面代码中的问题是什么不起作用

标签: javascriptphaser-framework

解决方案


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])

推荐阅读