如何在Phaser中将位图数据固定到相机? [英] How can I fix bitmapdata to the camera in Phaser?

查看:74
本文介绍了如何在Phaser中将位图数据固定到相机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在相位器中使用位图数据和摄像头时遇到了麻烦.

我正在将相机作为游戏的一部分进行移动,因为它是滚动游戏.我正在使用bitmapdata绘制运行状况栏,但它一直在屏幕外滚动. :/ 到目前为止,我已经尝试过:

•将fixedToCamera属性设置为true

•使用move属性将其与滚动一起移动

•制作精灵并将其作为子级添加到位图数据中,并将fixedToCamera属性设置为true

我将位图数据添加到sprite的代码:

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

我收到以下错误:

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)

解决方案

尝试这样做:

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

这是位图数据精灵的官方示例.

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)

解决方案

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.

这篇关于如何在Phaser中将位图数据固定到相机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆