admin管理员组文章数量:1300022
I am very new at Phaser. I want my Game to be as big as the Website is. Following code scaled the Phaser Gamefield to the websites height and width:
width = window.innerWidth * window.devicePixelRatio;
height = window.innerHeight * window.devicePixelRatio;
var config = {
type: Phaser.AUTO,
width: width,
height: height,
scene: [mainMenu]
};
Now the canvas is scaled to the Screen, but the objects are not. Funny thing: When I resize the Website to 80%, then everything fits perfectly in. But when its on 100%, then the Background-Image is not plete and test is not where I placed it.
Now I searched for ways to perfectly resize the Phaser Gamefield, but found nothing. At this time my understanding of Phaser is too small to Do this on my own. I hope somebody can explain how I can scale my Game in Phaser.
I am very new at Phaser. I want my Game to be as big as the Website is. Following code scaled the Phaser Gamefield to the websites height and width:
width = window.innerWidth * window.devicePixelRatio;
height = window.innerHeight * window.devicePixelRatio;
var config = {
type: Phaser.AUTO,
width: width,
height: height,
scene: [mainMenu]
};
Now the canvas is scaled to the Screen, but the objects are not. Funny thing: When I resize the Website to 80%, then everything fits perfectly in. But when its on 100%, then the Background-Image is not plete and test is not where I placed it.
Now I searched for ways to perfectly resize the Phaser Gamefield, but found nothing. At this time my understanding of Phaser is too small to Do this on my own. I hope somebody can explain how I can scale my Game in Phaser.
Share Improve this question edited Dec 21, 2018 at 16:59 James Skemp 8,5819 gold badges70 silver badges112 bronze badges asked Dec 20, 2018 at 17:34 user10214015user102140151 Answer
Reset to default 8I usually build my games at a set size, then use the scale: {}
property to change how it scales to the window size.
In my example below, the original game is 1280x720, but the scale mode makes it fit the window. This should scale you're game objects as well.
let config = {
width: 1280,
height: 720,
// Sets game scaling
scale: {
// Fit to window
mode: Phaser.Scale.FIT,
// Center vertically and horizontally
autoCenter: Phaser.Scale.CENTER_BOTH
},
scene: []
};
There are many other types of scale modes, which you can see on Phaser's API documentation here: https://photonstorm.github.io/phaser3-docs/Phaser.Scale.html
Hope this has helped!
本文标签: javascriptPhaser 3 Scaling the Game to full Websites width and heightStack Overflow
版权声明:本文标题:javascript - Phaser 3: Scaling the Game to full Websites width and height - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741651930a2390529.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论