【发布时间】:2021-12-09 12:55:52
【问题描述】:
我正在制作一个剑游戏,你必须收集硬币才能变大,然后与人战斗。这是我到目前为止所拥有的:
注意玩家在收集硬币时如何变大。一段时间后,你会变得大到可以覆盖整个屏幕。
我意识到我必须根据玩家的大小缩小相机。
这就是我的相机(在创建功能中)
this.cameras.main.startFollow(this.mePlayer);
我在它之前添加了这行代码:
this.cameras.main.setZoom(0.5)
现在变成了这样。文字都变小了,出于某种原因,我的 tileSprite 背景也坏了。
这是文本的代码。
//killcounter
this.killCount = this.add.text(window.innerWidth / 1.5, 0, 'Kills: 0', {
fontFamily: 'Georgia, "Goudy Bookletter 1911", Times, serif'
}).setFontSize(40).setDepth(101);
this.killCount.scrollFactorX = 0
this.killCount.scrollFactorY = 0
//player+fpscounter
this.playerCount = this.add.text(this.cameras.main.worldView.x*this.cameras.main.zoom, this.cameras.main.worldView.y*this.cameras.main.zoom, 'Players: 0' + "\nFPS: 0", {
fontFamily: 'Georgia, "Goudy Bookletter 1911", Times, serif'
}).setFontSize(20).setDepth(101);
this.playerCount.scrollFactorX = 0
this.playerCount.scrollFactorY = 0
这是我相机的代码
this.cameras.main.startFollow(this.mePlayer);
...这是我的背景代码
//in create function
this.background = this.add.tileSprite(0, 0, window.innerWidth, window.innerHeight, 'background').setOrigin(0).setScrollFactor(0, 0);
this.background.fixedToCamera = true;
//in update function
this.background.setTilePosition(this.cameras.main.scrollX, this.cameras.main.scrollY);
有没有一种方法可以锁定文本,以便当相机缩小时,它会保持在同一位置?
【问题讨论】:
标签: javascript camera zooming game-development phaser-framework