【问题标题】:Zoom out camera while keeping text locked - Phaser 3在保持文本锁定的同时缩小相机 - Phaser 3
【发布时间】: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


    【解决方案1】:

    感谢 samme 帮我解决这个问题。

    最后我创建了另一个名为 UICamera 的相机。

    我使用ignore 函数忽略了该相机上的所有游戏对象。

    我忽略了主相机上的所有文本、小地图、ui 和tilesprite 背景。

    然后,要缩小,我只需缩小主摄像头并手动调整 tileSprite 比例。

    http://phaser.io/examples/v3/view/camera/ignore

    【讨论】:

      猜你喜欢
      • 2014-08-19
      • 1970-01-01
      • 1970-01-01
      • 2016-08-23
      • 2018-11-12
      • 2021-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多