How can I fix bitmapdata to the camera in Phaser?

2019-08-10 19:55发布

I'm having some trouble with bitmapdata and the camera in Phaser.

I'm moving the camera as part of my game because it's a scrolling game. I'm using bitmapdata to draw a health bar, but it keeps scrolling offscreen. :/ So far I've tried:

• Setting the fixedToCamera property to true

• Using the move property to move it along with the scrolling

• Making a sprite and adding the bitmapdata to it as a child and setting the fixedToCamera property to true

My code for adding the bitmapdata to the sprite:

bitmap = Game.make.bitmapData(800, 100)
bitmap.addToWorld(0, 0)
bitmapSprite = Game.add.sprite(0, 0)
bitmapSprite.addChild(bitmap)

I get the following error:

Uncaught TypeError: this.children[t].updateTransform is not a function
    at i.Sprite.s.DisplayObjectContainer.updateTransform (phaser.min.js:3)
    at i.World.s.DisplayObjectContainer.updateTransform (phaser.min.js:3)
    at i.Stage.updateTransform (phaser.min.js:3)
    at i.Game.updateLogic (phaser.min.js:3)
    at i.Game.update (phaser.min.js:3)
    at i.RequestAnimationFrame.updateRAF (phaser.min.js:3)
    at window.requestAnimationFrame.forceSetTimeOut._onLoop (phaser.min.js:3)

1条回答
Summer. ? 凉城
2楼-- · 2019-08-10 20:39

Try doing it like this:

bitmap = game.add.bitmapData(800, 100);
bitmapSprite = game.add.sprite(0, 0, bitmap);
bitmapSprite.fixedToCamera = true;

Here is the official example for bitmapdata sprites.

查看更多
登录 后发表回答