如何在智能手机和平板电脑中缩放Phaser 3游戏及其资产的功能?[英] How to scale a Phaser 3 game and their assets to it works in smartphones and tablets?

问题描述

我是与Phaser 3和ApacheCórdova一起创建移动Android游戏的新公司.

我创建了一个1200 x 800 PX的游戏.平板电脑看起来不错,但智能手机却没有.如何将其扩展到多个屏幕尺寸?

此外,我还需要帮助强迫使用Phaser3.

来实现游戏取向.

谢谢

推荐答案

function create () {
    window.addEventListener('resize', resize);
    resize();
}

function resize() {
    var canvas = game.canvas, width = window.innerWidth, height = window.innerHeight;
    var wratio = width / height, ratio = canvas.width / canvas.height;

    if (wratio < ratio) {
        canvas.style.width = width + "px";
        canvas.style.height = (width / ratio) + "px";
    } else {
        canvas.style.width = (height * ratio) + "px";
        canvas.style.height = height + "px";
    }
}

其他推荐答案

控制屏幕方向,请在Android项目的构建/SRC/MAIN目录中添加以下内容.每次您从电容器等包装创建者进行重建时,这都会消失,因此每次生成Android项目时都需要替换它.

 <application
        ...
        android:screenOrientation="landscape"
        >

        <activity
            ...
            android:screenOrientation="landscape">
            ...
        </activity>
</application>

本文地址:https://www.itbaoku.cn/post/1740213.html