2017-02-18 8 views
0

私はこのバグを表示するためにcodepenを作成しました。フェーザー矩形波動の振る舞い

更新機能:

update: function(){ 
    this.timeBar.width = this.timeBar.width - 1; 

だけ幅を変更するように設定されています。しかし、それをクロムで見ると、ポジションも変わるようです。これはバグですか、それともこのコードを書いている間に私が考慮しなかったものなのでしょうか?

+0

は、スタックオーバーフローへようこそ!あなたの質問の完全な内容は、リンクされているだけでなく**あなたの質問で**なければなりません。リンクが腐って、将来の質問やその回答が役に立たなくなり、人々はあなたを助けるためにオフサイトに行く必要はありません。スタックスニペット( '<>'ツールバーボタン)を使用して理想的に[mcve] **を実行可能にします。その他:[*どのように良い質問をしますか?](/ help/how-to-ask) –

+0

Thxはリンク形式を削除します。 –

答えて

0

これは、グラフィックスを使用して、やや複雑になることができますが、私はのBitmapDataを使った例を見つけました:

create: function(){ 
    var bmd = this.game.add.bitmapData(300, 40); 
     bmd.ctx.beginPath(); 
     bmd.ctx.rect(0, 0, 300, 80); 
     bmd.ctx.fillStyle = '#00685e'; 
     bmd.ctx.fill(); 

    var bglife = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, bmd); 
    bglife.anchor.set(0.5); 

    bmd = this.game.add.bitmapData(280, 30); 
    bmd.ctx.beginPath(); 
     bmd.ctx.rect(0, 0, 300, 80); 
     bmd.ctx.fillStyle = '#FFFFFF'; 
     bmd.ctx.fill(); 

    this.widthLife = new Phaser.Rectangle(0, 0, bmd.width, bmd.height); 
    this.totalLife = bmd.width; 

    this.life = this.game.add.sprite(this.game.world.centerX - bglife.width/2 + 10, this.game.world.centerY, bmd); 
    this.life.anchor.y = 0.5; 
    this.life.cropEnabled = true; 
    this.life.crop(this.widthLife); 

    this.scheduler = this.game.time.events.loop(1500, this.cropLife, this); 
    }, 

    cropLife: function(){ 
    if(this.widthLife.width <= 0){ 
     this.widthLife.width = this.totalLife; 
     this.scheduler.stop(); 
    } 
    else{ 
     this.game.add.tween(this.widthLife).to({ width: (this.widthLife.width - (this.totalLife/10)) }, 200, Phaser.Easing.Linear.None, true); 
    } 
    }, 

    update: function(){ 
    this.life.updateCrop(); 
    } 

You can see the discussion in detail here

+0

グラフィックを削除して再描画することで、これを別の方法で解決しましたが、助けてくれてありがとう – GuruYaya