LostRoutes项目日志——在main.js中添加多分辨率适配
初始的Cocos2d-JS项目中的main.js代码的内容为:
/**
* A brief explanation for "project.json":
* Here is the content of project.json file, this is the global configuration for your game, you can modify it to customize some behavior.
* The detail of each field is under it.
{
"project_type": "javascript",
// "project_type" indicate the program language of your project, you can ignore this field "debugMode" : 1,
// "debugMode" possible values :
// 0 - No message will be printed.
// 1 - cc.error, cc.assert, cc.warn, cc.log will print in console.
// 2 - cc.error, cc.assert, cc.warn will print in console.
// 3 - cc.error, cc.assert will print in console.
// 4 - cc.error, cc.assert, cc.warn, cc.log will print on canvas, available only on web.
// 5 - cc.error, cc.assert, cc.warn will print on canvas, available only on web.
// 6 - cc.error, cc.assert will print on canvas, available only on web. "showFPS" : true,
// Left bottom corner fps information will show when "showFPS" equals true, otherwise it will be hide. "frameRate" : 60,
// "frameRate" set the wanted frame rate for your game, but the real fps depends on your game implementation and the running environment. "noCache" : false,
// "noCache" set whether your resources will be loaded with a timestamp suffix in the url.
// In this way, your resources will be force updated even if the browser holds a cache of it.
// It's very useful for mobile browser debuging. "id" : "gameCanvas",
// "gameCanvas" sets the id of your canvas element on the web page, it's useful only on web. "renderMode" : 0,
// "renderMode" sets the renderer type, only useful on web :
// 0 - Automatically chosen by engine
// 1 - Forced to use canvas renderer
// 2 - Forced to use WebGL renderer, but this will be ignored on mobile browsers "engineDir" : "frameworks/cocos2d-html5/",
// In debug mode, if you use the whole engine to develop your game, you should specify its relative path with "engineDir",
// but if you are using a single engine file, you can ignore it. "modules" : ["cocos2d"],
// "modules" defines which modules you will need in your game, it's useful only on web,
// using this can greatly reduce your game's resource size, and the cocos console tool can package your game with only the modules you set.
// For details about modules definitions, you can refer to "../../frameworks/cocos2d-html5/modulesConfig.json". "jsList" : [
]
// "jsList" sets the list of js files in your game.
}
*
*/ cc.game.onStart = function(){
if(!cc.sys.isNative && document.getElementById("cocosLoading")) //If referenced loading.js, please remove it
document.body.removeChild(document.getElementById("cocosLoading")); // Pass true to enable retina display, on Android disabled by default to improve performance
cc.view.enableRetina(cc.sys.os === cc.sys.OS_IOS ? true : false); // Adjust viewport meta
cc.view.adjustViewPort(true); // Uncomment the following line to set a fixed orientation for your game
// cc.view.setOrientation(cc.ORIENTATION_PORTRAIT); // Setup the resolution policy and design resolution size
cc.view.setDesignResolutionSize(960, 640, cc.ResolutionPolicy.SHOW_ALL); // The game will be resized when browser size change
cc.view.resizeWithBrowserSize(true); //load resources
cc.LoaderScene.preload(g_resources, function () {
cc.director.runScene(new HelloWorldScene());
}, this);
};
cc.game.run();
main.js(origional)
删除一些注释,main.js看的清晰一些:
cc.game.onStart = function(){
if(!cc.sys.isNative && document.getElementById("cocosLoading")) //If referenced loading.js, please remove it
document.body.removeChild(document.getElementById("cocosLoading"));
cc.view.enableRetina(cc.sys.os === cc.sys.OS_IOS ? true : false);
cc.view.adjustViewPort(true);
cc.view.setDesignResolutionSize(960, 640, cc.ResolutionPolicy.SHOW_ALL);
cc.view.resizeWithBrowserSize(true);
cc.LoaderScene.preload(g_resources, function () {
cc.director.runScene(new HelloWorldScene());
}, this);
};
cc.game.run();
不过这里还要做一些修改,然后修改后的代码如下:
cc.game.onStart = function () {
cc.view.setDesignResolutionSize(640, 960, cc.ResolutionPolicy.SHOW_ALL);
cc.view.resizeWithBrowserSize(true);
cc._loaderImage = res.loading_jpg;
//load resources
cc.LoaderScene.preload(g_resources, function () {
cc.director.runScene(new HomeScene());
}, this);
};
cc.game.run();
这里还有一些东西没有修改,比如初始的Scene不是HelloworldScene而是HomeScene(虽然这个HomeScene现在还没有,但是马上就会有的)
这里还有一个问题是资源文件是640x960的,所以在web项目和android项目中运行的项目实际上看起来是如下图所示的,因为一般屏幕的宽度比高度要大所以这里会看到左右两边的黑色区域,但是因为这样的话能看到整个游戏场景,我个人感觉测试起来还是挺清晰的,所以还是选择SHOW_ALL。

LostRoutes项目日志——在main.js中添加多分辨率适配的更多相关文章
- 在vue项目中的main.js中直接使用element-ui中的Message 消息提示、MessageBox 弹框、Notification 通知
需求来源:向后台请求数据时后台挂掉了,后台响应就出现错误,不做处理界面就卡住了,这时需要在main.js中使用axios的响应拦截器在出现相应错误是给出提示.项目使用element-ui,就调用里面的 ...
- main.js中封装全局登录函数
1. 在 main.js 中封装全局登录函数 通过 vue 对象的原型扩展,可以扩展一个函数,这样这个函数就可以在每一个界面通过类似指向对象的方式,去访问这个函数. 如下是 main.js 扩展的函数 ...
- main.js中import引入css与引入js的区别
表现:引入css样式文件能够作用到全局,而引入js文件就只能在main.js中产生作用 在 main.js 中引入的 css 都是全局生效的.引入的 js 文件只在 main.js 中生效,是因为 m ...
- 一道面试题关于js中添加动态属性
js中数据类型包含基本数据类型和引用类型,基本类型包括:string.null.undefined.number.boolean.引用类型即是对象比如:array .function以及自定义对象等 ...
- LostRoutes项目日志——玩家飞机精灵Fighter解析
Fighter类的定义在Fighter.js中,Fighter类继承与PhysicsSprite. 原版的Fighter.js: var Fighter = cc.PhysicsSprite.exte ...
- LostRoutes项目日志——敌人精灵Enemy解析
Enemy类在Enemy.js中,类Enemy类继承自PhysicsSprite,以便于可以使用物理引擎中的一些特性. 原版的Enemy.js: var Enemy = cc.PhysicsSprit ...
- 如何在其他js 引入main.js 中 vue 的实例?
1.原因解析 经测试发现,代码先执行了 index.js >> main.js >> Home.vue scr/api/index.js src/main.js src/co ...
- bootstrap table 生成的表格里动态添加HTML元素按钮,JS中添加点击事件,点击没反应---解决办法
bootstraptable中onExpandRow属性---js 方法添加的 html代码,然后给这代码里面的 元素 添加 事件,却获取不该元素.(称之为未来元素),由于是未来的 所以现在没有这个 ...
- 项目开发---使用node.js中sass语法
前言:本文中所有sass文件都指后缀名为scss的文件.在此也建议使用后缀名为scss的文件,以避免sass后缀名的严格格式要求报错. 一.sass插件的安装: gulp-sass-china // ...
随机推荐
- ThreadLocal 简介 案例 源码分析 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- Java循环一个对象的所有属性,并通过反射给这些属性赋值/取值
Java循环一个对象的所有属性,并通过反射给这些属性赋值/取值 说到循环遍历,最常见的遍历数组/列表.Map等.但是,在开发过程中,有时需要循环遍历一个对象的所有属性.遍历对象的属性该如何遍历呢?查了 ...
- 用命令让vbox的虚拟硬盘文件转换成vmware的vmdk
VirtualBox的生成备份功能只是个系统还原点 这个生成备份功能备份速度非常快,其实它并不是备份,而是相当于xp系统中的建立系统还原点.但是要注意的是如果你的虚拟硬盘文件(***.vdi)在别的V ...
- Delphi读取不Word中不规则表格数据并转换成标准表格
程序需要,需要将word中不规则的表格数据转换为标准的表格,即合并的单元格按正常格式解析,word中的表格格式如下: 解析后数据如下: 借鉴了网上代码,如下处理: procedure TfrmMain ...
- Clipboard Action for Mac(智能剪贴板历史管理器)破解版安装
1.软件简介 Clipboard Action 是 macOS 系统上一款智能剪贴板历史管理器,它允许剪贴板历史中的每一段内容执行操作.使用 AppleScript 或 Automator 工作 ...
- php static 变量的例子
class test { public static function a(){} public function b(){} } $obj = new test; 调用 代码 test::a(); ...
- 分享一个Godaddy的优惠码,可以优惠35%——2013-11-23
国外的域名注册商就是好,还有优惠码,付费的时候贴上优惠码就能免相应的金额,不错. 在网上找的一个35%优惠的优惠码,可以买域名和主机.(主机就免了,有点贵,域名不错) 我买了个com域名,原本$12. ...
- html5 required属性的注意事项
实例 带有必填字段的表单: <form action="demo_form.asp" method="get"> Name: <input t ...
- 揭开Redis的神秘面纱
本篇博文将为你解开Redis的神秘面纱,通过阅读本篇博文你将了解到以下内容: 什么是Redis? 为什么选择 Redis? 什么场景下用Redis? Redis 支持哪些语言? Redis下载 Red ...
- 【Android】开源项目UniversalImageLoader及开源框架ImageLoader
UniversalImageLoader 简单来说就是用于加载图片的一个开源项目,在其项目介绍中是这么写的 支持多线程图片加载 提供丰富的细节配置,比如线程池大小,HTPP请求项,内存和磁盘缓存,图片 ...