最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to scale a Phaser 3 game and their assets to it works in smartphones and tablets? - Stack Overflow

programmeradmin4浏览0评论

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

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?

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

Thanks

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

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?

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

Thanks

Share Improve this question edited Jun 27, 2018 at 14:14 James Skemp 8,5819 gold badges70 silver badges112 bronze badges asked Jun 7, 2018 at 13:48 Rafael GallardoRafael Gallardo 1431 silver badge7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6
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";
    }
}

To control screen orientation, add the following to the applicationManifest xml in the build/src/main directory of your android project. This will disappear every time you rebuild from a package creator like capacitor, so you'll need to replace it every time you generate an android project.

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

        <activity
            ...
            android:screenOrientation="landscape">
            ...
        </activity>
</application>
发布评论

评论列表(0)

  1. 暂无评论