如何将Phaser 3游戏及其资产扩展到可在智能手机和平板电脑上使用的游戏? [英] How to scale a Phaser 3 game and their assets to it works in smartphones and tablets?

查看:96
本文介绍了如何将Phaser 3游戏及其资产扩展到可在智能手机和平板电脑上使用的游戏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new working with Phaser 3 and Apache Córdova for create mobile Android games.

我创建了一个1200 x 800像素的游戏.在平板电脑上看起来不错,但在智能手机上则不然.如何缩放以在多种屏幕尺寸下工作?

I have created a game of 1200 x 800 px. It looks fine in tablets but in smartphones doesn't. How can I scale it to work in multiple screen sizes?

此外,我需要帮助来强制使用Phaser 3调整游戏​​方向.

Additionally, I need help to force to landscape the game orientation using Phaser 3.

谢谢

推荐答案

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";
    }
}

这篇关于如何将Phaser 3游戏及其资产扩展到可在智能手机和平板电脑上使用的游戏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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