首先介绍一个api和相应的参数:
cc.view.setDesignResolutionSize(1024, 768, cc.ResolutionPolicy.FIXED_WIDTH);
这里设置游戏制作的目标尺寸和显示的模式。
模式包括:
cc.ResolutionPolicy = {// The entire application is visible in the specified area without trying to preserve the original aspect ratio.// Distortion can occur, and the application may appear stretched or compressed.EXACT_FIT:0,// The entire application fills the specified area, without distortion but possibly with some cropping,// while maintaining the original aspect ratio of the application.NO_BORDER:1,// The entire application is visible in the specified area without distortion while maintaining the original// aspect ratio of the application. Borders can appear on two sides of the application.SHOW_ALL:2,// The application takes the height of the design resolution size and modifies the width of the internal// canvas so that it fits the aspect ratio of the device// no distortion will occur however you must make sure your application works on different// aspect ratiosFIXED_HEIGHT:3,// The application takes the width of the design resolution size and modifies the height of the internal// canvas so that it fits the aspect ratio of the device// no distortion will occur however you must make sure your application works on different// aspect ratiosFIXED_WIDTH:4,UNKNOWN:5 };
参考官方说明: http://www.cocos2d-x.org/wiki/Multi_resolution_support
EXACT_FIT会拉伸游戏,充满整个屏幕,最简单最粗暴;
SHOW_ALL保持游戏原比例,让一边占满屏幕,另外一侧黑边;
NO_BORDER跟SHOW_ALL类似,但让短边占满屏幕,另外一侧超出屏幕,不显示黑边,一部分画面在屏幕外,无法显示;
FIXED_WIDTH和FIXED_HEIGHT都是NO_BORDER的升级版,指定那一侧充满屏幕,另外一侧超出屏幕。
这里建议使用FIXED_WIDTH和FIXED_HEIGHT,其他用法请参考:
转自:http://www.cnblogs.com/kenkofox/p/3951210.html
作者还推荐了腾讯的面试机会,具体见上一行这个链接。