├── .gitignore ├── 404.html ├── Gemfile ├── Gemfile.lock ├── README.md ├── _config.yml ├── _includes ├── comments.html ├── disqus.html ├── duosuo.html ├── footer.html ├── header.html ├── page.html ├── post.html ├── posts.html └── statistics.html ├── _layouts ├── index.html ├── page.html └── post.html ├── _posts ├── 2013-04-10-start-blog.md ├── 2013-04-11-base64.md ├── 2013-04-22-linux-file-permission.md ├── 2013-04-25-mklink.md ├── 2013-05-11-sh-execute-diff.md ├── 2013-05-12-buy-a-vps.md ├── 2013-05-13-a-xshell-style.md ├── 2013-05-23-thinking-from-shaver.md ├── 2013-05-26-difference-between-resume-and-cv.md ├── 2013-06-16-ifttt.md ├── 2013-08-01-ubuntu-static-ip-and-dns.md ├── 2013-09-25-simple-factory-pattern.md ├── 2013-09-27-polymorphic-factory-pattern.md ├── 2013-09-29-abstract-factory-pattern.md ├── 2013-09-30-singleton-pattern.md ├── 2013-12-25-mongoose.md ├── 2013-12-28-argparse.md ├── 2013-12-31-the-2013.md ├── 2014-01-09-samba.md ├── 2014-01-11-ubuntuone-command-line.md ├── 2014-10-16-centos-die-on-boot.md ├── 2014-10-21-python-import-test.md ├── 2014-12-29-python-reference.md ├── 2015-02-26-the-2014.md ├── 2015-09-27-uwsgi-fork-trap.md ├── 2015-11-08-raspberry-pi-first-time.md ├── 2016-06-10-texture-unpacker.md └── 2016-07-02-animations-and-spritesheets-in-cocos2d-x.md ├── about.md ├── archives.html ├── atom.xml ├── avater.html ├── categories.html ├── favicon.ico ├── feed.xml ├── images └── 2016 │ ├── animationphases.png │ ├── black-bars.png │ ├── device-stats.png │ ├── extended-scene.png │ ├── gamescene-animated.png │ ├── gamescene-capguy.png │ ├── gamescene-just-background.png │ ├── texturepacker-add-sprites.png │ ├── texturepacker-polygon-sprites.png │ ├── texturepacker-scaling-variants.png │ ├── texturepacker-select-cocos2d-x.png │ └── trim-and-polygon-trim.png ├── index.html ├── media ├── css │ ├── highlight.css │ └── style.css ├── img │ ├── favicon.png │ └── rss.png └── js │ └── base.js ├── photo.html ├── read.html ├── resume.html ├── tags.html └── wish.html /.gitignore: -------------------------------------------------------------------------------- 1 | _site/ 2 | .idea/ 3 | -------------------------------------------------------------------------------- /404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 |13 | foo/ 14 | ├── bar/ 15 | | ├── __init__.py 16 | | └── main.py 17 | ├── case.py 18 | ├── case1.py 19 | ├── case2.py 20 | ├── case3.py 21 | └── case4.py 22 |23 | 24 | #### 测试代码 25 | 26 | [likebeta/test](https://github.com/likebeta/test/tree/master/python/test_import) 27 | 28 | #### 运行结果 29 | 30 | ``` 31 | [mj@model_3 foo]$ python case.py 32 | case.py 33 | /home/work/foo/bar/__init__.py 34 | {'bar':
使用黑边, 分数显示在外面
147 | 148 |  149 | 150 |缩放场景
151 | 152 | 第一种方法可能是最好的,但是会增加大量的工作, 并且会影响到游戏展现,带来更大的挑战。 153 | 154 | 第二种看起来有点像90年代的设计。 155 | 156 | 我比较推荐第三种,它给玩家一致的体验。本教程的资源是为4:3宽高比做的,但是内容主要是针对16:9。 157 | 158 | #### 使用TexturePacker来创建精灵图表 159 | 160 | 首先从这里下载安装:https://www.codeandweb.com/texturepacker/download 161 | 162 | 拖拽cityscene文件夹到左侧面板,TexturePacker会添加包含的精灵到表中,并且保持文件的结构。当添加或者删除精灵图片是也会自动更新精灵表。 163 | 164 |  165 | 166 | `Data Format`选择`cocos2d-x`, 不要选择`cocos2d`,`cocos2d`不支持多边形打包。 167 | 168 |  169 | 170 | 开启多边形支持:`Trim mode`选择`polygon`, 你可以通过调节`Tracer tolerance`来控制精灵的多边形顶点数量,越多的顶点就可以越精确的标识非空白区域,减少绘制量, 但是尽量别控制顶点的数量, 以为顶点的计算需要消耗CPU的资源。 171 | 172 | 因为背景图片是个非透明矩形,所以这个精灵表过度绘制依然达到了95%。 173 | 174 |  175 | 176 | 为不同的分辨率设备添加缩放比例,右边面板点击`Scaling variants`选择`cocos2d-x HDR/HD/SD`,点击`Apply`,你会看到三个缩放比例:`/HDR/`不缩放,`/HD/`缩放比例 0.5 和`/SD/`缩放比例0.25。如果你不是你想要的, 你可以删除它们,点击`Close`返回精灵表。 177 | 178 | 你会看到3个tab标签,点击标签可以预览相应缩放比例的精灵表。 179 | 180 |  181 | 182 | 点击`Data file`后面的文件夹图标,将文件命名`cityscene.png`, 并保存在你工程下面的res目录中。你会得到一个错误,提示你需要在文件名中包含一个占位符`{v}`。 将文件名从`.../res/cityscene.plist`改为`.../res/{v}/cityscene.plist`。当保存文件的时候,这里的占位符会被替换成缩放比例的名字。 183 | 184 | 点击工具栏中的`Publish sprite sheet`,你将会在工程中看到6个文件: 185 | 186 | + res 187 | - HDR 188 | + cityscene.plist 189 | + cityscene.png 190 | - HD 191 | + cityscene.plist 192 | + cityscene.png 193 | - SD 194 | + cityscene.plist 195 | + cityscene.png 196 | 197 | #### AppDelegate中的启动代码 198 | 199 | 现在让我们开始写点代码吧。在开始使用精灵图表前,我们先来做点基础工作。如果`AppDelegate`中代码处理的好的话,可以让你游戏和分辨率保持解耦。 200 | 201 | #### 启动和分辨率处理 202 | 203 | 用以下代码替换`AppDelegate.h`中的代码: 204 | 205 | ``` 206 | #ifndef _APP_DELEGATE_H_ 207 | #define _APP_DELEGATE_H_ 208 | 209 | #include "cocos2d.h" 210 | 211 | class AppDelegate : private cocos2d::Application 212 | { 213 | public: 214 | virtual void initGLContextAttrs(); 215 | virtual bool applicationDidFinishLaunching(); 216 | virtual void applicationDidEnterBackground(); 217 | virtual void applicationWillEnterForeground(); 218 | 219 | private: 220 | void initOpenGL(); 221 | void initMultiResolution(); 222 | void initDirector(); 223 | void createAndRunScene(); 224 | }; 225 | 226 | #endif 227 | ``` 228 | 229 | 程序会在不同的时机调用这些`public`虚函数,你需要实现定义在`ApplicationProtocol`中的纯虚函数。这里的`private`函数帮助我们更好的组织整个过程。 230 | 231 | 删除并用以下代码替换`AppDelegate.cpp`中的内容: 232 | 233 | ``` 234 | #include "AppDelegate.h" 235 | #include "HelloWorldScene.h" 236 | 237 | USING_NS_CC; 238 | 239 | static cocos2d::Size designResolutionSize = cocos2d::Size(2048, 1536); 240 | 241 | static cocos2d::Size smallResolutionSize = cocos2d::Size(512, 384); 242 | static cocos2d::Size mediumResolutionSize = cocos2d::Size(1024, 768); 243 | static cocos2d::Size largeResolutionSize = cocos2d::Size(2048, 1536); 244 | ``` 245 | 246 | `designResolutionSize`表示游戏的设计大小。你可以根据自己的需要随意设置它,不过业界用的比较多的下面两个值: 247 | 248 | 1. (512, 384): 在低分辨率设备中1单元对应1像素 249 | 2. (2048x1536): 在你的设计中1单元对应1像素 250 | 251 | 在cocos2d-x中想做到像素级别的完美设计很困难,最简单的原因,如果你想在Android设备上运行游戏, 你就需要面对大量的不同分辨率设备,就连iOS的设备大小和比例也都不同。 252 | 253 | 我个人比较建议使用高分辨率作为`designResolutionSize`, 因为这样能更容易的在图形编辑器中权衡和设置大小和位置。 但是如果一个对象放置的坐标位置不能被4整除,可能会低分辨率设备上有点误差。但是考虑到缩放,其实并不是个大问题。 254 | 255 | `smallResolutionSize`,`mediumResolutionSize`and`largeResolutionSize`这3个值表示不同屏幕的设备提供的缩放的设计尺寸。他们会对应`TexturePacker`打包成的缩放版的精灵表。 256 | 257 | 添加下面的函数, 它负责加载缩放版本的图片资源。 258 | 259 | ``` 260 | void AppDelegate::initMultiResolution() 261 | { 262 | auto director = Director::getInstance(); 263 | auto glview = director->getOpenGLView(); 264 | 265 | glview->setDesignResolutionSize( 266 | designResolutionSize.width, 267 | designResolutionSize.height, 268 | ResolutionPolicy::NO_BORDER 269 | ); 270 | 271 | ... 272 | ``` 273 | 274 | `setDesignResolutionSize`用来设置游戏的设计尺寸,`ResolutionPolicy::NO_BORDER`表示场景会被拉升填满整个屏幕, 该参数还有几个值可以选择: 275 | 276 | 值 | 描述 277 | ------------ | ----------- 278 | EXACT_FIT | 拉升填充整个屏幕,但不是宽高等比拉升,某些情况整个画面是扭曲变形的。 279 | NO_BORDER | 等比拉升,填满整个屏幕,可能超出屏幕外,有些部分不可见 280 | SHOW_ALL | 等比拉升,但是不会超出屏幕外,如果比例不一样,就用黑边填充两边的空白区域 281 | FIXED_HEIGHT | 以高为准,宽进行缩放适配 282 | FIXED_WIDTH | 以宽为准,高进行缩放适配 283 | 284 | 实际使用中`EXACT_FIT`基本上都不会采用,`NO_BORDER`可能是最简单的方法了。 285 | 286 | 继续补充`initMultiResolution()`函数: 287 | 288 | ``` 289 | ... 290 | 291 | std::vector11 | . . 12 | .:@3@@@@X@@A.#3,A@M5r 13 | i@M@@@@@@@@@@@@@@@@@@@@@@@@ 14 | .,#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#5@@ 15 | i@@@@@@#@##M@#M###@@@#@@@@@@@@@@@@@@@@@H;: 16 | 2@@@@@#MB#@@H#@@@@#@@@@@@@@#@@@@@@@@@@@@@@@@; 17 | ;@@@@MBB##B@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#. 18 | h@@@MHBMM@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 19 | @@@HABM@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 20 | ;@@@#AHB@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@:. 21 | .@@@@HM@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 22 | ,@@#HAAH#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@r 23 | r@MAM@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@i 24 | h@#H@@@@@@@@@@@@@M#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@S 25 | ;@@AAAGM@@@@@@@@S, ., .rri9@AXHi2:.S;.9sr@M&HA9XXH@@@@@@@@@@@@@@@ 26 | @#AAABM@@@@@#. ;@@@@@@@@@@@ 27 | S@MAA&A@@@@@s ,... ........ B@@@@@@@@@ 28 | @MAAA@@@@@ ........... .... .;:::::::::::,,,, M@@@@@@@@i 29 | 2@HAA@@@. ...........................;:::::::::::::::: @@@@@@@@A 30 | ;@BAAAA@@@ ............................;:::::::::::::::;: @@@@@@@@. 31 | ,@MAA@@@ ...........................:;:::::::::::::::::,.@@@@@@@@# 32 | ,@#AAH#@@@ . ..............;;::::,. ,:::,.@@@@@@@@; 33 | ;@M&M@@@@@. .:;rrssiir;, .......... ::. ,;5hHAS3: .::.,@@@@@@@@@ 34 | ;@MAH@@@@@ ;@@@@@@@@@@@@@@9. ......... r&@@@@@@@@@@@@,,:..@@@@@@@@ 35 | ,@MA@@@@A ;@@MHAAAAAAA#@@@@; ...... ;@@@@@@@@@@@@@@@@2.:, @@@@@@@@r 36 | G@AH@@@H ,;;rsiSS55iss;:r: .,,,:::,AGr;rrrrsisr;:. . . 5@@@@@@# 37 | s@AM@@@.,#@@@@#&GAB@@##H@@@@@Bi:,:::,:SB@@@#M#@@@@@@@@@@#i @@@@@@@ 38 | .@@H@@@@@@@r H@@@X#@&r. ,i#@@@@@@@@@@Hs.:XA@9G@#3X..sM@@@@,5@@@@@@ 39 | ;@@@@@@@@& :@A.5@9@@s,X2 &@@@HM@@r .@52@A@@A.;SG. M@@@@@@@@@. 40 | @@@@@@@; .:, :,,:, , &@s :@@ ,. :,. , :... ,@@@@@@@@s 41 | 3@@& #@i . isi: ,..@@ @@A ...;2ii; . .: r@@@@@@@# 42 | &h: 5: @@M: .,r@@, . ;@@s .,..@@h;@#iss2G 43 | @5 X: h@@@@@@@@@####@@@@@@, . ., r@@@@Ms:,....,;;rsh@@X G ,X@ 44 | SB rr: @, ,r2hH#@@@@@@@#i. ....,, ;3#@@@@@@@@@@@@@@#; M ..,;.M& 45 | #;;H9MS#. .. ,. .,:::;;;::. ,, @.:&HX,;@ 46 | #:.,..S@, .. .,. ... ,,, .::: #iBr ,:@ 47 | 29 :,,i@s ......... ,;,:;;. ... . .:, .;:: @@rr5s.s# 48 | @: ,MiiA ..............,;:;@sr;MM:,::;h@X.rH,:;,..... . .;:: @i;rsh,@. 49 | @r : ;@ ............:;; rA9;SMr;;;;Gh2H#; .;,....::,. .;:, # :@; 50 | H9 @; .....,,,,::;r;: ,;;:. .. .......,;r;;::;:.;H ,r&A 51 | rHS.&A .....,rrrr;;:. ..........:;;;;:: MB5&5. 52 | :rX@ .......... ... . ,35S ....,, .... :;::::,@; 53 | @; ..... .:s. ..,,..:;,.,,.... ;i, .... .;:::.iG 54 | ;@ ..........;H@HAAAAAA&32Xh&&AAA&AAG@G;:.... ,;::: @, 55 | @r ..........,,,:,,,,. .,,.. .,:;;:.::.... :;::.i# 56 | .@, ....... ,r:,,,:;i23r,,, ....:;::,:@ 57 | r@,. ........ ,SG&&&hXir;::: ......:;::,:@: 58 | i@;,. ............. ,,,..,,,:::,........:;::.;@, 59 | ;@9:,. ........... ... .......;;:,:GM. 60 | 9@X:. ........... .......,;;,;hM; 61 | h@&;. ........................:;::sAA; 62 | iB#X;. ...............,,:;::r3B3, 63 | .iH#Gi:.. .,,::::::;:::r2A&r 64 | ;XABA3S;;;;;;;;;rsiXG3r 65 | ,rS@AAAAAAAA&X#M 66 | #:.,:,,,,. rG 67 | ,@,.,::::,,,:@, 68 | .sAr@. ...:::,.@@HAi 69 | A@@h 3, .;::.2X @@@i 70 | G@@@; ... ,;::,.,.@@@@2 71 | 5@@H@@, .:,,::::, #@B#@#3 72 | ,@@#HM@@2:. ,,....,s@@HA#@ @; 73 | X.r#AAAAMHh2isiiii53AMHAAA#2,:9 74 |75 |
18 | {{ post.content | split:'' | first | strip_html }} 19 | [继续阅读] 20 |
21 |