I have a problem on Phaser3.
I developing a 2D platform game with Phaser3. And this game must be fit and playable on every mobile device with different resoulution.
My base game config is (I developing many games so I had wrote a base config for use on each game):
import Phaser, { Types } from "phaser";
const ratio = window.innerWidth < 600 ? 2 : 1;
const baseGameConfig: Types.Core.GameConfig = {
type: Phaser.WEBGL,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
width: window.innerWidth * ratio,
height: window.innerHeight * ratio,
},
render: {
antialias: true,
},
};
export default baseGameConfig;
And my game config is:
import { Types } from "phaser";
import baseGameConfig from "@games/config.base";
import Scenes from "./src/scenes";
const gameConfig: Types.Core.GameConfig = {
...baseGameConfig,
title: "platform2d",
scene: Scenes.BootScene.scene,
physics: {
default: "arcade",
arcade: {
debug: process.env.NODE_ENV !== "production",
gravity: {
y: 600,
},
},
},
};
export default gameConfig;
I using tilemaps, tilesets etc. in this game but I don't know how can I fit this tiles on the screen on every device. I research on internet but I didn't find any solution for this. All of them write the screen size like 800x600.
There is my tilemap as a json file:
{ "compressionlevel":-1,
"height":20,
"infinite":false,
"layers":[
{
"data":[...],
"height":20,
"id":1,
"name":"background",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":30,
"x":0,
"y":0
},
{
"data":[...],
"height":20,
"id":2,
"name":"wall",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":30,
"x":0,
"y":0
}],
"nextlayerid":3,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.10.2",
"tileheight":16,
"tilesets":[
{
"columns":10,
"firstgid":1,
"image":"grass.png",
"imageheight":128,
"imagewidth":160,
"margin":0,
"name":"grass",
"spacing":0,
"tilecount":80,
"tileheight":16,
"tilewidth":16
},
{
"columns":8,
"firstgid":81,
"image":"wall",
"imageheight":128,
"imagewidth":128,
"margin":0,
"name":"wall",
"spacing":0,
"tilecount":64,
"tileheight":16,
"tilewidth":16
}],
"tilewidth":16,
"type":"map",
"version":"1.10",
"width":30
}
By the way I know I defined this tilemap a fixed width & height but like I said I don't know how can I do this in Phaser3.
There is a pictures of different resolution:
I also used Phaser.Scale.RESIZE mode but when I used that mode, my assets' quality decreased because I must shrank scale of all assets otherwise they looked so big and overflow from screen.
I just want to scalable and same look this tiles, assets on every mobile device.
Thanks.