-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
790 lines (346 loc) · 26.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>/无间落叶</title>
<meta name="author" content="一叶">
<meta name="description" content="在游戏的开发过程中,前期的规划 往往比 后期的“优化”更为重要!比如多分辨率适配,如果前期没有规划好,可能导致的情况是,画面只在当前测试开发机或者一部分机型正常显示。做了多套资源适配,可以使在合适的机型使用对应的图片资源,避免在高清屏幕使用低质量的图片,在低分辨率屏幕因为图片太大而浪费硬件资源。 …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://blog.leafsoar.com/index.html">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="/javascripts/ender.js"></script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<link href="/atom.xml" rel="alternate" title="/无间落叶" type="application/atom+xml">
<!-- font-family: 'Knewave', cursive; -->
<link href='http://fonts.useso.com/css?family=Knewave' rel='stylesheet' type='text/css'>
<!-- font-family: 'Cantata One', serif; -->
<link href='http://fonts.useso.com/css?family=Cantata+One' rel='stylesheet' type='text/css'>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-34041741-6']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<a href="https://github.com/leafsoar" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="/images/github.png" alt="Fork me on GitHub"></a>
<body >
<header role="banner"><hgroup>
<h1>
<a href="/">/无间落叶</a>
<span>I am a leaf on the wind ~</span>
</h1>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
<li><a href="http://weibo.com/leafsoar" rel="subscribe-weibo" title="subscribe via weibo" target="_blank">
<img src="/images/weibo_icon.png" width="26" height="21" alt="weibo" title="weibo" />
</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:blog.leafsoar.com" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Home</a></li>
<li><a href="/blog/archives">Archives</a></li>
<li><a href="/cocos2d-x">Cocos2d-x</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div class="blog-index">
<article>
<header>
<h1 class="entry-title"><a href="/archives/2013/11-27.html">如何优雅的管理游戏资源</a></h1>
<p class="meta">
<time datetime="2013-11-27T20:56:00+08:00" pubdate data-updated="true">Nov 27<span>th</span>, 2013</time>
| <a href="/archives/2013/11-27.html#disqus_thread">Comments</a>
|
<span class="categories">
<a class='category' href='/archives/category/cocos2d-x/'>Cocos2d-x</a>
</span>
</p>
</header>
<div class="entry-content"><p>在游戏的开发过程中,<strong>前期的规划 往往比 后期的“优化”更为重要!</strong>比如多分辨率适配,如果前期没有规划好,可能导致的情况是,画面只在当前测试开发机或者一部分机型正常显示。做了多套资源适配,可以使在合适的机型使用对应的图片资源,避免在高清屏幕使用低质量的图片,在低分辨率屏幕因为图片太大而浪费硬件资源。机制与策略分离,可以让你设计出简单有效的接口。模块化的设计可以让你组织好各种逻辑流程,条理分明 ~ 前期的规划工作可以有很多,一叶也在摸索之中,以使游戏的开发尽量变的简单灵活且可控。最简单的也是最容易忽略的地方,跟我们打交道最多的要数精灵了,从图片创建一个精灵,很简单的开端,将以此展开行动 ~</p>
<p>本文使用 Cocos2d-3.0alpha1 版本,创建了一个 C++ 项目,介绍在 C++ 中,如何处理资源相关的内容,如果读者使用脚本,也可以参考本文中资源管理理念而忽略语言特性,你可以在 Github<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> 上面看到本文所有源码。</p>
</div>
<footer>
<a rel="full-article" href="/archives/2013/11-27.html">Read more →</a>
</footer>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/archives/2013/11-10.html">玩转 Cocos2d-x 脚本引擎</a></h1>
<p class="meta">
<time datetime="2013-11-10T20:56:00+08:00" pubdate data-updated="true">Nov 10<span>th</span>, 2013</time>
| <a href="/archives/2013/11-10.html#disqus_thread">Comments</a>
|
<span class="categories">
<a class='category' href='/archives/category/cocos2d-x/'>Cocos2d-x</a>
</span>
</p>
</header>
<div class="entry-content"><p>在 Unix 文化中,有这样一种理念,Happy Hacking!使用 Cocos2d-x/C++ 写过一些游戏,其绑定的脚本语言,用的也不少,脚本语言的一个好处就是快速开发,你无需明白它之运行机理,便可容易的完成所想要的效果,三天上手,五天就能写出像样的程序来,C++ 则不然,其各种语言细节特性,各种开发技巧,内存管理等细枝末叶 ~</p>
<p>计算机不会魔法,在一叶看来其内容,只有 <strong>“知、或者不知”</strong> ,没有 <strong>“懂、或者不懂”</strong>,“知或者不知”来自于你的学习历程与经验,至于“不懂”么,我还没接触到的领域内容,我都不懂,哈 ~ Cocos2d-x 脚本引擎也用过一段时间了,但其运行机理还不明白,就使用而言也无需明白,不过于在意细节的实现,可能更好的从宏观角度把握整体。过去只是对其“存疑”(对于这里的“不懂”,一叶通常美其名曰:<strong>要学会存疑</strong> :p ),而现在想要对其运行机制多了解一些,那就只有一步步去探究喽,要了解到什么程度,那就随意了~</p>
<p>对 Cocos2d-x 的运行机制只是略懂一二,C++ 的场景由 C++ 运行,脚本呢,先开启脚本引擎,让后将控制权交由脚本代码执行,在这过程中发生了什么,由脚本所控制的元素和 C++ 有什么不同,或者说它的本质是什么!这之前一叶一直说的是脚本引擎,而非具体那种脚本引擎,lua 或者 js (jsvascript)的引擎实现!凭着对已有知识的了解和直觉,很多疑问和可能性随之而来,它所支持的脚本语言有两种,此两种的共同之处是什么,其使用了脚本绑定技术,<strong>什么是绑定</strong> ?各种对象在内存中如何分布,如何配合在一起工作。</p>
<p>为了增加探究过程的趣味性,所以一叶试想着能不能让 Cocos2d-x 现今所支持的<strong>两种脚本引擎同时运行</strong> (lua and js),然后确定是否能在三者之间(C++, js, lua)访问同一个内存元素,如果行,便弄出来,即便不能做到,那也无所谓,这其中的过程比结果更有意思,不是吗 ~</p>
</div>
<footer>
<a rel="full-article" href="/archives/2013/11-10.html">Read more →</a>
</footer>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/archives/2013/07-27.html">CCScrollView 实现帮助界面、关卡选择</a></h1>
<p class="meta">
<time datetime="2013-07-27T17:30:00+08:00" pubdate data-updated="true">Jul 27<span>th</span>, 2013</time>
| <a href="/archives/2013/07-27.html#disqus_thread">Comments</a>
|
<span class="categories">
<a class='category' href='/archives/category/cocos2d-x/'>Cocos2d-x</a>
</span>
</p>
</header>
<div class="entry-content"><p>本文介绍了 CCScrollView 来编写帮助界面和关卡选择界面的方法,在编写这样一个功能之时,大多会遇到一些困难,这里也是同样,最后提供了一个相应且合理的解决方案,并解说了其它实现方案的优缺点,这里的内容,你可以直接拿去用,或者可以作为实现的参考。总能找到你需要的东西,或多~或少~。文章大致内容如下:</p>
<ul>
<li>首先实现了一个可拖动的界面,滚屏屏幕,它可以用于完成帮助界面的设计</li>
<li>接着实现了关卡选择功能,这里的着重点是 <strong>如何处理触摸机制</strong> 。以达到不错的协同工作</li>
<li>由于是分屏滚动,所以完成了一个页索引 “指示球功能”</li>
</ul>
<p>本文所使用的 Cocos2d-x 为当前的稳定版本 2.1.4。(如无说明,文章内容总是配合 当前最新 稳定版库)
原来是使用 Cocos2d-x 2.0.4 编写的功能,周末花了点事件进行了整理 和 重构(触摸机制的重构)。</p>
</div>
<footer>
<a rel="full-article" href="/archives/2013/07-27.html">Read more →</a>
</footer>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/archives/2013/06-04.html">深入理解 Cocos2d-x 内存管理</a></h1>
<p class="meta">
<time datetime="2013-06-04T10:50:00+08:00" pubdate data-updated="true">Jun 4<span>th</span>, 2013</time>
| <a href="/archives/2013/06-04.html#disqus_thread">Comments</a>
|
<span class="categories">
<a class='category' href='/archives/category/cocos2d-x/'>Cocos2d-x</a>
</span>
</p>
</header>
<div class="entry-content"><p>如果 <a href="http://blog.leafsoar.com/archives/2013/05-22.html">Cocos2d-x 内存管理浅说</a> 做为初步认识,而 <a href="http://blog.leafsoar.com/archives/2013/05-29.html">Cocos2d-x 内存管理的一种实现</a>做为进阶使用,那么本文将详细的分析一下 Cocos2d-x 的内存管理的设计实现和原理。<strong>知其然,知其所以然 ~</strong>或者说:嗯,它这么做,一定是有原因的,体会设计者的用意,感同身受,如果是你,将会如何设计!~~</p>
<p>我觉得 <strong>最好的学习方式是以自己的语言组织,说与别人听 ~</strong> 这样对自己:更容易发现平时容易忽略的问题,对别人:或多或少也有所助益!以学习为目的,而别人的受益算是附带的效果,这样一个出发点 ~</p>
<p>由浅入深,总览全局(或者由整体到局部)是我喜欢的出发点,或者思考角度,我不喜欢拘泥于细节的实现,因为那会加大考虑问题的复杂度,所以 <strong>把复杂的问题简单化,是必然的过程。</strong> 那么本文就说说 Cocos2d-x 的架构是如何设计以方便内存管理的。从理论到实践 ~(当然是从我看问题的角度 :P,读者如有异议,欢迎讨论!文本使用 cocos2d-x 2.0.4 解说。)</p>
</div>
<footer>
<a rel="full-article" href="/archives/2013/06-04.html">Read more →</a>
</footer>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/archives/2013/05-29.html">Cocos2d-x 内存管理的一种实现</a></h1>
<p class="meta">
<time datetime="2013-05-29T10:10:00+08:00" pubdate data-updated="true">May 29<span>th</span>, 2013</time>
| <a href="/archives/2013/05-29.html#disqus_thread">Comments</a>
|
<span class="categories">
<a class='category' href='/archives/category/cocos2d-x/'>Cocos2d-x</a>
</span>
</p>
</header>
<div class="entry-content"><p>使用 Cocos2d-x 编写游戏,常被人吐槽,吐槽什么,当然是内存管理,C++ 的使用本以不易,而在 Cocos2d-x 添加了半内存自动管理,在这么一种 <strong>复合机制</strong> 下,使得出现内存问题的概率直线飙升 ~</p>
<p>而关于这一点,可能在于并没有一个通用的合理的内存管理方式,能够更好的使用 Cocos2d-x ,或者说,缺少那么一种 <strong>规范</strong>,如果存在了这么一种 <strong>规范</strong>,而使得 Cocos2d-x 更为简单优雅,那势必是游戏的开发过程,更加从新所欲,把重点放在游戏本身的设计之上。</p>
<h2>Retain 与 Release 乃万恶之源</h2>
<p>稍微了解一点就能知道 Cocos2d-x 是基于引用计数来管理内存的,应用计数的加减就是 retain 和 release 方法的实现。在大多数情况下我们不用 <strong>显示</strong> 的去调用这两种方法,如在 <strong>CCNode</strong> 的 <strong>addChild</strong> 和 <strong>removeChild</strong> 方法,<strong>CCArray</strong> 的 <strong>addObject</strong> 和 <strong>removeObject</strong> 等这样成双成对的方法,对于这些的使用很简单,一叶上篇文章 <strong><a href="http://blog.leafsoar.com/archives/2013/05-22.html">Cocos2d-x 内存管理浅说</a></strong> 从概念上简单的分析了内部对象的生命周期特点,在此 <strong>浅说</strong> 之中,我刻意的绕过了它的底层实现,并没有深究其原理,对引用计数等概念也只是几句话一带而过,重点放在使用者该关心什么,该注意什么。因为我觉得 <strong>引用计数是个坑,一个很大的坑 ~</strong></p>
</div>
<footer>
<a rel="full-article" href="/archives/2013/05-29.html">Read more →</a>
</footer>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/archives/2013/05-25.html">多层 UI 触摸事件的轻量级设计</a></h1>
<p class="meta">
<time datetime="2013-05-25T10:10:00+08:00" pubdate data-updated="true">May 25<span>th</span>, 2013</time>
| <a href="/archives/2013/05-25.html#disqus_thread">Comments</a>
|
<span class="categories">
<a class='category' href='/archives/category/cocos2d-x/'>Cocos2d-x</a>
</span>
</p>
</header>
<div class="entry-content"><p><strong>轻量级</strong>:一叶非常喜欢的名词,在重量级和轻量级之间,如果做选择的话,一定会选择轻量级,它的特点首先是设计简单小巧,使用方便,更具有灵活性,扩展方便。重量级则大而丰富,全面,但略显笨重,在程序设计之初大多需要全盘考虑。而轻重之间的概念是相对而言,并没有严格的界限。</p>
<h2>Cocos2d-x 触摸事件机制概论</h2>
<p>在 cocos2d-x 使用触摸来触发一些操作是很常用的功能,如果界面非常简单,只需要启用相应层的触摸功能,并处理其触摸事件即可,而如果界面的 UI 复杂,多层管理,又有着隐藏控制,灵活多变,比如 MMO 游戏,当然手游不会 <strong>那么</strong> 复杂,那么现有的机制实现起来就显得捉襟见肘了,即便实现,也很难维护,而一个简单的方式是 <strong>只在场景的 基层 接受触摸消息,然后由此基层向上层发送触摸的消息</strong>,上层再根据实际情况进行处理,判断可触摸元素优先级,是否隐藏,返回处理结果,再一层层向下传递,保证实际的操作是我们所期望的。</p>
</div>
<footer>
<a rel="full-article" href="/archives/2013/05-25.html">Read more →</a>
</footer>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/archives/2013/05-22.html">Cocos2d-x 内存管理浅说</a></h1>
<p class="meta">
<time datetime="2013-05-22T23:30:00+08:00" pubdate data-updated="true">May 22<span>nd</span>, 2013</time>
| <a href="/archives/2013/05-22.html#disqus_thread">Comments</a>
|
<span class="categories">
<a class='category' href='/archives/category/cocos2d-x/'>Cocos2d-x</a>
</span>
</p>
</header>
<div class="entry-content"><p>使用过 Cocos2d-x 都知道,其中有一套自己实现的内存管理机制,不同于一般 C++ 的编写常规,而在使用前,了解其原理是有必要的,网上已经有很多对内部实现详细解说的文章。而对于使用者而言,并不需要对其内部有很深的了解,注重其<strong>“机制”</strong>,而非内部实现,在这里只是简单的聊一聊它的管理方式以及使用,固为浅说。</p>
<h2>无用对象 与 管理对象</h2>
<p><strong>Cocos2d-x 将会在下一帧自动清理无用的对象,什么是无用的对象,通过 create() 方法创建的就是无用的对象。</strong></p>
<p>为了简要说明,代码的组织设计一切从简,我们创建了两个辅助类和一个容器类 BaseLayer,在 BaseLayer 之上管理内部对象,并观察它是怎么自动管理对象的。实现了其 构造函数 方法和 析构函数,并做些日志打印,以方便我们观察:</p>
</div>
<footer>
<a rel="full-article" href="/archives/2013/05-22.html">Read more →</a>
</footer>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/archives/2013/05-15.html">类 Android 多级日志系统应用</a></h1>
<p class="meta">
<time datetime="2013-05-15T17:30:00+08:00" pubdate data-updated="true">May 15<span>th</span>, 2013</time>
| <a href="/archives/2013/05-15.html#disqus_thread">Comments</a>
|
<span class="categories">
<a class='category' href='/archives/category/cocos2d-x/'>Cocos2d-x</a>
</span>
</p>
</header>
<div class="entry-content"><p>在 cocos2d-x 中实现类 Android 多级日志系统!写程序,免不了调试打印 Log ,而一个方便的日志系统,可以提高不少开发的效率,写过 Android 应用的朋友应该了解在 Android 中的日志包含很多等级,查看日志的时候可以指定日志的级别,从而过滤一些无用的信息,能够更为快速的定位问题的所在。而在 cocos2d-x 的开发中,统一使用 <strong>CCLog</strong>,只能算是最基本的功能,既然有好的思想可以借鉴,何乐而不为呢~</p>
<p>先看看最终实现的效果,我们使用简单封装过的方法调用打印日志系统(Leafsoar Log:LSLog):</p>
</div>
<footer>
<a rel="full-article" href="/archives/2013/05-15.html">Read more →</a>
</footer>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/archives/2013/05-13.html">Cocos2d-x 屏幕适配新解 - 兼容与扩展</a></h1>
<p class="meta">
<time datetime="2013-05-13T08:02:00+08:00" pubdate data-updated="true">May 13<span>th</span>, 2013</time>
| <a href="/archives/2013/05-13.html#disqus_thread">Comments</a>
|
<span class="categories">
<a class='category' href='/archives/category/cocos2d-x/'>Cocos2d-x</a>
</span>
</p>
</header>
<div class="entry-content"><p>在读这篇文章之前,先读前一篇文章 <a href="http://blog.leafsoar.com/archives/2013/05-10.html">Cocos2d-x 屏幕适配新解</a> 是必要的。</p>
<p>如果说前一篇文章文章在 LsSize 提出之前的是基础,LsSize 是应用,那么对于这篇文章来说,LsSize 是基础,而这里是其的综合应用,我之初衷是其扩展性和兼容性,激发读者思维。也许你并没有体会出 LsSize 的强大,而实际上,<strong>它能做的比你想象的要多的多,这是前话 ~</strong></p>
<h2>ShoAll 模式的兼容</h2>
<p>首先 LsSize 能满足 ShowAll 模式的需要,因为开始就是把 LsSize 当作 ShowAll 中的 WinSize 来设计的。 并且可以为背景做装饰,而在游戏设计之时并没有什么区别,LsSize 可以设定显示区域的大小,使背景层与 LsSize 分离(这一点在上一篇文章最后已经提到),从而保证了游戏的元素不会超出 LsSize 而露出到 VisibleSize 的区域内。</p>
</div>
<footer>
<a rel="full-article" href="/archives/2013/05-13.html">Read more →</a>
</footer>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/archives/2013/05-10.html">Cocos2d-x 屏幕适配新解</a></h1>
<p class="meta">
<time datetime="2013-05-10T19:02:00+08:00" pubdate data-updated="true">May 10<span>th</span>, 2013</time>
| <a href="/archives/2013/05-10.html#disqus_thread">Comments</a>
|
<span class="categories">
<a class='category' href='/archives/category/cocos2d-x/'>Cocos2d-x</a>
</span>
</p>
</header>
<div class="entry-content"><p>为了适应移动终端的各种分辨率大小,各种屏幕宽高比,在 cocos2d-x(当前稳定版:<strong>2.0.4</strong>) 中,提供了相应的解决方案,以方便我们在设计游戏时,能够更好的适应不同的环境。</p>
<p>而在设计游戏之初,决定着我们屏幕适配的因素有哪些,简而言之只有两点:<strong>屏幕大小 和 宽高比</strong>。这两个因素是如何影响游戏的:</p>
<ul>
<li><strong>屏幕大小:</strong> 从小分辨率 <strong>480x320</strong> 到 <strong>1280x800</strong> 分辨率,再到全高清 <strong>1080p</strong>,从手机到平板,还有苹果设备的 <strong>Retina</strong> 屏,这么多不同的分辨率,而且大小差距甚大,不可能做到一套资源走天下,资源往小了设计,在大屏幕会显示模糊,图片往大了设计,在小屏幕设备又太浪费,而且小屏幕的手机硬件资源也会相对的紧缺,所以 <strong>根据屏幕大小使用不同的资源</strong> 是有必要的,而 cocos2d-x 也帮我们解决了这一点。</li>
<li><strong>宽高比:</strong> 什么是宽高比,就是你的屏幕是方的还是长的,靠近方形的分辨率如 480x320,比例为 <strong>3:2</strong>,还有 960x540 的 <strong>16:9</strong> 标准宽屏,这也算是两种总极端情况了,如果能在这两种比例情况做好适配基本就可以了,如果比 3:2 “更方”如 4:3,比 16:9 “更长”,那么不论如何布局,显示效果差距甚大,最好对固定比例优化吧。当在宽高比在一定范围内,可以通过灵活编写程序去适应,而在显示效果上,cocos2d-x 为我们提供了三种模式,这些 <strong>模式更多的是帮我们解决比例不一的情况而存在</strong> 的,如果只是屏幕大小(比例一样),那通过简单的放大缩小即可完成。</li>
</ul>
</div>
<footer>
<a rel="full-article" href="/archives/2013/05-10.html">Read more →</a>
</footer>
</article>
<div class="pagination">
<a class="prev" href="/archives/page/2/">← Older</a>
<a href="/blog/archives">Blog Archives</a>
</div>
</div>
<aside class="sidebar">
<section class="first odd">
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/archives/2013/11-27.html">如何优雅的管理游戏资源</a>
</li>
<li class="post">
<a href="/archives/2013/11-10.html">玩转 Cocos2d-x 脚本引擎</a>
</li>
<li class="post">
<a href="/archives/2013/07-27.html">CCScrollView 实现帮助界面、关卡选择</a>
</li>
<li class="post">
<a href="/archives/2013/06-04.html">深入理解 Cocos2d-x 内存管理</a>
</li>
<li class="post">
<a href="/archives/2013/05-29.html">Cocos2d-x 内存管理的一种实现</a>
</li>
</ul>
</section>
<section>
<h1>GitHub Repos</h1>
<ul id="gh_repos">
<li class="loading">Status updating…</li>
</ul>
<a href="https://github.com/leafsoar">@leafsoar</a> on GitHub
<script type="text/javascript">
$.domReady(function(){
if (!window.jXHR){
var jxhr = document.createElement('script');
jxhr.type = 'text/javascript';
jxhr.src = '/javascripts/libs/jXHR.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(jxhr, s);
}
github.showRepos({
user: 'leafsoar',
count: 0,
skip_forks: true,
target: '#gh_repos'
});
});
</script>
<script src="/javascripts/github.js" type="text/javascript"> </script>
</section>
</aside>
</div>
</div>
<footer role="contentinfo"><p>
Copyright © 2014 - 一叶 -
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a> and <a href="https://github.com/gluttony/object-octopress-theme">Object</a></span>
</p>
</footer>
<script type="text/javascript">
var disqus_shortname = 'leafsoar';
var disqus_script = 'count.js';
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}());
</script>
</body>
</html>