摘要:巨坑在内不要把设为在内不要把设为在内不要把设为重要的事情得说三遍接收更多游戏开源教学为游戏开发深感自豪
巨坑:
在config内不要把 width 设为 window.innnerWidth
在config内不要把 width 设为 window.innnerWidth
在config内不要把 width 设为 window.innnerWidth
重要的事情得说三遍...
</>复制代码
var game;
// once the window loads...
window.onload = function () {
// 接收 websocket;
// config of the game;
var config = {
type: Phaser.AUTO,
parent: "bitgame",
width: 640, // don"t window.innerWidth
height: 512,
physics: {
default: "arcade",
arcade: {
gravity: {
y: 0
},
debug: false,
}
},
//*** scenes used by the game
scene: [BootScene,PlayGameScene,UIScene]
}
game = new Phaser.Game(config);
// game.scene.add("Boot", BootScene); //*** key,class */
// game.scene.add("PlayGame", PlayGameScene);
// game.scene.add("UI", UIScene);
// game.scene.start("Boot");
window.focus();
resize();
window.addEventListener("resize", resize, false);
}
function resize() {
var canvas = document.querySelector("canvas");
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var windowRatio = windowWidth / windowHeight;
var gameRatio = game.config.width / game.config.height;
if (windowRatio < gameRatio) {
canvas.style.width = windowWidth + "px";
canvas.style.height = (windowWidth / gameRatio) + "px";
} else {
canvas.style.width = (windowHeight * gameRatio) + "px";
canvas.style.height = windowHeight + "px";
}
}
更多游戏开源教学:www.iFIERO.com -- 为游戏开发深感自豪
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/99062.html
摘要:巨坑在内不要把设为在内不要把设为在内不要把设为重要的事情得说三遍接收更多游戏开源教学为游戏开发深感自豪 showImg(https://segmentfault.com/img/remote/1460000016934375); 巨坑:在config内不要把 width 设为 window.innnerWidth在config内不要把 width 设为 window.innnerWid...
摘要:在文末,我会附上一个可加载的模型方便学习中文艺术字渲染用原生可以很容易地绘制文字,但是原生提供的文字效果美化功能十分有限。 showImg(https://segmentfault.com/img/bVWYnb?w=900&h=385); WebGL 可以说是 HTML5 技术生态链中最为令人振奋的标准之一,它把 Web 带入了 3D 的时代。 初识 WebGL 先通过几个使用 Web...
showImg(https://segmentfault.com/img/remote/1460000016964470); showImg(https://segmentfault.com/img/remote/1460000016964471); scene.js /// use strict; var BootScene = new Phaser.Class({ Extends...
阅读 2186·2021-10-12 10:12
阅读 847·2021-09-24 09:47
阅读 1330·2021-08-19 11:12
阅读 3557·2019-08-29 13:06
阅读 789·2019-08-26 11:43
阅读 2664·2019-08-23 17:20
阅读 1212·2019-08-23 16:52
阅读 2679·2019-08-23 14:27
极致性价比!云服务器续费无忧!
Tesla A100/A800、Tesla V100S等多种GPU云主机特惠2折起,不限台数,续费同价。
NVIDIA RTX 40系,高性价比推理显卡,满足AI应用场景需要。
乌兰察布+上海青浦,满足东推西训AI场景需要