2017-02-18 42 views
0

我創建了codepen來顯示此錯誤。Phaser矩形標記行爲

更新函數:

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

設置爲僅改變寬度。但是,在鉻上查看它似乎也改變了立場。這是一個錯誤,還是它只是我沒有考慮到的東西,而編寫這些代碼?

+0

歡迎堆棧溢出!你的問題的全部內容必須在**你的問題中**,而不僅僅是鏈接。鏈接腐爛,使問題及其答案在未來的人們中毫無用處,人們不應該離開現場去幫助你。在**問題中放置一個[mcve] **,最好使用Stack Snippets('<>'工具欄按鈕)使其可運行。更多:[*我如何問一個好問題?*](/幫助/如何問) –

+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