【问题标题】:Animations not starting once in Phaser.js动画在 Phaser.js 中没有开始一次
【发布时间】:2018-05-14 03:40:30
【问题描述】:

我使用移相器 2.6.1。

我创建了一个动画。这工作正常,但有时动画没有开始。我不知道为什么。

create() 函数中,我为我的精灵表添加动画:

this.car = game.add.sprite(game.world.centerX,500, 'car');
this.car.animations.add('mover',[0,1,2,3],1000, true);
this.car.fixedToCamera = true;

当重叠时,我启动函数来动画:

game.physics.arcade.overlap(this.car, this.borders, this.canMove, null, this);

这是我的功能:

},canMove: function(car, objet){
    if(crash == 0){
        crash = 1;
        _this.car.animations.play("mover");
                console.log("fire")
        setTimeout(function(){
            _this.car.animations.stop();
            _this.car.frame = 0;
            crash = 0;
        },1000)
    }
}

当汽车与边界重叠时,触发此功能。

console.log() 被触发,但动画突然没有开始。我可以重新启动我的页面很多时间,但即使触发了console.log(),动画也没有开始。

【问题讨论】:

  • 你能贴出你的代码sn-p吗?
  • 在这里发布你的全部代码
  • 好的,我已经添加了所有代码
  • 动画在“canMove”功能上开始
  • 我的其他代码已经有这个问题了

标签: javascript jquery phaser-framework


【解决方案1】:

问题是因为我首先用 :

初始化了我的汽车
this.car = game.add.sprite(game.world.centerX,500, 'car');
this.car.animations.add('mover',[0,1,2,3],1000, true);
this.car.fixedToCamera = true;
_this = this

在我的函数之后,我直接用_this 调用我的车

我使用了_this,因为在setTimeout() 内部,this 属性不等于文档的this

我不知道为什么,但如果我先用this 初始化,然后用_this 调用,这将无法正常工作。另外为了解决我的问题,我直接从_this 开始。

_this = this;
_this.car = game.add.sprite(game.world.centerX,500, 'car');
_this.car.animations.add('mover',[0,1,2,3],1000, true);
_this.car.fixedToCamera = true;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-30
    • 2023-04-04
    相关资源
    最近更新 更多