Uncaught TypeError: this._tweens [i] .update не является функцией в Phaser.TweenManager.update - PullRequest
1 голос
/ 17 октября 2019

Я работаю с фазером 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();

В чем проблема в приведенном выше коде, который не работает

1 Ответ

0 голосов
/ 18 октября 2019
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 args являются следующими:

to(properties [, duration] [, ease] [, autoStart] [, delay] [, repeat] [, yoyo])
...