创建项目: For(MAC)
Runtime Requirements
- Android 2.3 or newer
- iOS 5.0 or newer
- OS X 10.7 or newer
- Windows 7 or newer
- Linux Ubuntu 12.04 (or newer)
- cocos2d-x v3.0rc(or newer)
Software
Requirements
- Xcode 4.6 (for iOS or Mac)
- gcc 4.7 for Linux or Android. For Android ndk-r9 or newer is required.
- Visual Studio 2012 (for Windows)
- Python 2.7.5
Create
A New Project
$ cd cocos2d-x
$ ./setup.py
$ source ~/.bash_profile # may be ~/.bash_login or ~/.profile, depends on your environemnt
$ cocos new MyGame -p com.MyCompany.MyGame -l cpp -d ~/MyCompany
-
MyGame
: name of your project -
-p com.MyCompany.MyGame
: package name for android -
-l cpp
: programming language used for the project, valid
value iscpp
andlua
-
-d ~/MyCompany
: directory to hold your project
Folder structure of the generated project is as following:
(Note: The directory may be different when the project type is lua.)
Build
And Run New Project
$ cocos run -s ~/MyCompany/MyGame -p ios
-
-s
: directory of the new project. This could be an absolute
path or a relative path. -
-p
: which platform to run on. Options areios
,android
,win32
,mac
andlinux
.
(Note: You are a tmux user, you should add reattach-to-user-namespace
before
the command cocos
. For more information, please refer to this
link for more information.)
You can run cocos run --help
for more detail information.
体验变化:
1、以CC开头的类从此去掉CC。如:
1
2
3
4
5
|
<code>| 1
0
|
|
|
|
|
举个样例,创建一个精灵的方式:
1
2
3
4
5
6
|
v2. 0
CCSprite*
v3. 0
auto
|
2、clone() 替代 copy(), 这个我用的不多。所以也就不多交代了;
3、Director的单例换成getInstance() 和 destroyInstance();
1
2
3
4
|
<code>| 1
0
|
|
|
|
|
4、新的触摸机制,先贴一段代码给大家看看,可能是下一篇或者下下篇我会具体讲下新的触摸机制的。(嘻嘻。搞得我好像非常牛逼哄哄的样子)
1
2
3
4
5
6
7
8
9
10
11
12
|
auto "file.png" );
...
auto
listener->setSwallowTouch( true );
listener->onTouchBegan return
;
listener->onTouchMoved
listener->onTouchEnded
listener->onTouchCancelled
//
EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener,
//
EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, 100 ); //
|
5、另一些杂七杂八的东西,本人理解的不透。也就不发出来献丑了。最后将CCType.h 里的一些变动贴出来,让我们愉快的结束这篇博文。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<code>| 1
0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</code>
|
一些全局的定义:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
//
ccColor3B 0 , 0 , 0 );
ccc3BEqual(color3B, 1 , 1 , 1 ));
ccColor4B 0 , 0 , 0 , 0 );
ccColor4F 0 , 0 , 0 , 0 );
color4F
color4F
ccc4FEqual(color4F, 1 , 1 , 1 , 1 ));
color4B
color3B
//
Color3B 0 , 0 , 0 );
color3B.equals(Color3B( 1 , 1 , 1 ));
Color4B 0 , 0 , 0 , 0 );
Color4F 0 , 0 , 0 , 0 );
color4F
color4F
color4F.equals(Color4F( 1 , 1 , 1 , 1 ));
color4B
color3B
|
继续...
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
|
<code>| 1
0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|