-
Notifications
You must be signed in to change notification settings - Fork 1
/
ccpointarray.html
134 lines (119 loc) · 6.17 KB
/
ccpointarray.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
<!DOCTYPE html>
<html dir="ltr" class="js desktop" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>ccpointarray</title>
<script>
(function(H) {
H.className = H.className.replace(/\bno-js\b/, 'js')
})(document.documentElement)
</script>
<link rel="stylesheet" type="text/css" href="css.css">
<script type="text/javascript" charset="utf-8" src="js.js"></script>
</head>
<body>
<!--[if lte IE 7 ]><div id="IE7"><![endif]-->
<!--[if IE 8 ]><div id="IE8"><![endif]-->
<div id="dokuwiki__site">
<div id="dokuwiki__top" class="dokuwiki site mode_show ">
<!-- ********** HEADER ********** -->
<div id="dokuwiki__header">
<div class="pad group">
<hr class="a11y">
</div>
</div>
<!-- /header -->
<div class="wrapper group">
<!-- ********** CONTENT ********** -->
<div id="dokuwiki__content"><div class="pad group">
<div class="pageId"><span>zh_cn:api:ccpointarray</span></div>
<div class="page group">
<!-- wikipage start -->
<h1 class="sectionedit1" id="ccpointarray">CCPointArray</h1>
<div class="level1">
<p>
CCPointArray 是一个用来容纳多个 CCPoint 对象的容器,方便一次性传递多个 CCPoint 对象。
</p>
<p>
~~
</p>
<p>
对象继承关系:
<a href="ccobject.html" class="wikilink1" title="zh_cn:api:ccobject">CCObject</a> -> CCPointArray
</p>
<p>
~~
</p>
<p>
主要用法:
</p>
<pre class="code lua"><span class="co1">-- 创建一个 CCPointArray 对象,并预留 100 个点的内存空间</span>
<span class="co1">-- 如果省略参数则不会预留内存空间</span>
<span class="kw1">local</span> points <span class="sy0">=</span> display<span class="sy0">.</span>newPointArray<span class="br0">(</span><span class="nu0">100</span><span class="br0">)</span>
<span class="co1">-- 添加 100 个点,如果点的数量超过 CCPointArray 已有的容量,CCPointArray 会自动扩展</span>
<span class="kw1">for</span> i <span class="sy0">=</span> <span class="nu0">1</span><span class="sy0">,</span> <span class="nu0">100</span> <span class="kw1">do</span>
points<span class="sy0">:</span>add<span class="br0">(</span>CCPoint<span class="br0">(</span><span class="nu0">100</span><span class="sy0">,</span> <span class="nu0">100</span><span class="br0">)</span><span class="br0">)</span>
<span class="kw1">end</span>
<span class="co1">-- 插入一个点到指定位置,注意位置索引是从 0 开始计算</span>
points<span class="sy0">:</span>insert<span class="br0">(</span>CCPoint<span class="br0">(</span><span class="nu0">200</span><span class="sy0">,</span> <span class="nu0">200</span><span class="br0">)</span><span class="sy0">,</span> <span class="nu0">0</span><span class="br0">)</span>
<span class="co1">-- 替换指定位置的点</span>
points<span class="sy0">:</span>replace<span class="br0">(</span>CCPoint<span class="br0">(</span><span class="nu0">300</span><span class="sy0">,</span> <span class="nu0">300</span><span class="br0">)</span><span class="sy0">,</span> <span class="nu0">1</span><span class="br0">)</span>
<span class="co1">-- 取得指定位置的点</span>
<span class="kw1">local</span> point <span class="sy0">=</span> points<span class="sy0">:</span>get<span class="br0">(</span><span class="nu0">10</span><span class="br0">)</span>
<span class="co1">-- 返回点的数量</span>
<span class="kw1">local</span> count <span class="sy0">=</span> points<span class="sy0">:</span>count<span class="br0">(</span><span class="br0">)</span>
<span class="co1">-- 删除指定位置的点,后续的点会自动前移</span>
points<span class="sy0">:</span><span class="kw3">remove</span><span class="br0">(</span><span class="nu0">10</span><span class="br0">)</span>
<span class="co1">-- 删除所有点</span>
points<span class="sy0">:</span>removeAll<span class="br0">(</span><span class="br0">)</span>
<span class="co1">-- 翻转所有点的顺序,返回一个新的 CCPointArray 对象</span>
<span class="kw1">local</span> pointsReversed <span class="sy0">=</span> points<span class="sy0">:</span>reverse<span class="br0">(</span><span class="br0">)</span>
<span class="co1">-- 翻转 CCPointArray 对象中所有点的顺序</span>
points<span class="sy0">:</span>reverseInline<span class="br0">(</span><span class="br0">)</span></pre>
</div>
<!-- wikipage stop -->
</div>
<div class="docInfo">zh_cn/api/ccpointarray.txt · Last modified: 2013/08/19 16:23 by Yu Lei Liao</div>
</div></div>
<!-- /content -->
<hr class="a11y">
<!-- PAGE ACTIONS -->
<div id="dokuwiki__pagetools">
<h3 class="a11y">Page Tools</h3>
<div class="tools">
<ul>
<li>
<a href="index.html" class="action backlink" rel="nofollow" title="home">
<span>home</span>
</a>
</li>
<li>
<a href="#dokuwiki__top" class="action top" accesskey="t" rel="nofollow" title="Back to top [T]">
<span>Back to top</span>
</a>
</li>
</ul>
</div>
</div>
</div>
<!-- /wrapper -->
</div>
</div>
<!-- /site -->
<div class="no">
<img src="zh_cn_api%20%5Bquick-cocos2d-x%20docs%5D_files/indexer.gif" alt="" height="1" width="2">
</div>
<div id="screen__mode" class="no"></div>
<!--[if ( lte IE 7 | IE 8 ) ]></div><![endif]-->
</body>
</html>