admin管理员组文章数量:1401167
import Phaser from 'phaser';
import PlayScene from './PlayScene';
import PreloadScene from './PreloadScene';
import QuestionScene from './QuestionScene';
import NotificationBannerScene from './NotificationBannerScene';
import backgroundImage from './assets/backgroundtest.svg';
// Apply the background image to the body
document.body.style.background = `url(${backgroundImage}) no-repeat center center / cover`;
const Scenes = [
PreloadScene,
PlayScene,
QuestionScene,
NotificationBannerScene
];
const createScene = Scene => new Scene()
const initScenes = () => Scenes.map(createScene)
const { screen, innerWidth, innerHeight, devicePixelRatio: dpr } = window;
const width = dpr === 1
? screen.width
: innerWidth * dpr;
const height = dpr === 1
? screen.height
: innerHeight * dpr;
const config = {
type: Phaser.CANVAS,
transparent: true,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
parent: 'game-container',
width: width,
height: height
},
physics: {
default: 'arcade'
},
scene: initScenes()
};
new Phaser.Game(config);
I have the above index.js then I use this.scale.width and this.scale.height for scaling sprite my problem now is if the user starts from portrait to landscape it become distorted. Right now I'm planning to use landscape size of mobile in portrait and landscape is this ok? or is there a better way?
import Phaser from 'phaser';
import PlayScene from './PlayScene';
import PreloadScene from './PreloadScene';
import QuestionScene from './QuestionScene';
import NotificationBannerScene from './NotificationBannerScene';
import backgroundImage from './assets/backgroundtest.svg';
// Apply the background image to the body
document.body.style.background = `url(${backgroundImage}) no-repeat center center / cover`;
const Scenes = [
PreloadScene,
PlayScene,
QuestionScene,
NotificationBannerScene
];
const createScene = Scene => new Scene()
const initScenes = () => Scenes.map(createScene)
const { screen, innerWidth, innerHeight, devicePixelRatio: dpr } = window;
const width = dpr === 1
? screen.width
: innerWidth * dpr;
const height = dpr === 1
? screen.height
: innerHeight * dpr;
const config = {
type: Phaser.CANVAS,
transparent: true,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
parent: 'game-container',
width: width,
height: height
},
physics: {
default: 'arcade'
},
scene: initScenes()
};
new Phaser.Game(config);
I have the above index.js then I use this.scale.width and this.scale.height for scaling sprite my problem now is if the user starts from portrait to landscape it become distorted. Right now I'm planning to use landscape size of mobile in portrait and landscape is this ok? or is there a better way?
Share Improve this question edited Mar 24 at 1:15 Barmar 784k57 gold badges548 silver badges660 bronze badges asked Mar 24 at 0:44 Newboy11Newboy11 3,1448 gold badges30 silver badges48 bronze badges1 Answer
Reset to default 0It depends on your game, gamelayout, logic,... but I would, just have Scenes for Portrait and Scenes fos Landscape, on the switch event (screen.orientation
), I would than transition to the other version of the Scene.
I usually try to I prevent rotation, with modals or
lock
.
本文标签:
版权声明:本文标题:javascript - In phaser 3 what is the efficient way to transition from portrait to landscape and vice versa - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744264571a2597885.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论