How can I fix bitmapdata to the camera in Phaser?

家住魔仙堡 提交于 2019-12-11 07:58:22

问题


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:


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.



来源:https://stackoverflow.com/questions/46695098/how-can-i-fix-bitmapdata-to-the-camera-in-phaser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!