@leejungkiin/awkit 1.5.5 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/bin/awk.js +188 -8
  2. package/core/GEMINI.md +15 -7
  3. package/core/work-modes.json +45 -0
  4. package/package.json +1 -1
  5. package/skill-packs/cocos2d/pack.json +8 -0
  6. package/skill-packs/cocos2d/skills/cocos2d-x/LICENSE.txt +8 -0
  7. package/skill-packs/cocos2d/skills/cocos2d-x/SKILL.md +168 -0
  8. package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/action.md +278 -0
  9. package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/animation.md +220 -0
  10. package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/event.md +133 -0
  11. package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/input.md +291 -0
  12. package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/label.md +184 -0
  13. package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/node-scene.md +212 -0
  14. package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/scene.md +228 -0
  15. package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/sprite.md +206 -0
  16. package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/texture.md +186 -0
  17. package/skill-packs/cocos2d/skills/cocos2d-x/examples/getting-started/about-engine.md +53 -0
  18. package/skill-packs/cocos2d/skills/cocos2d-x/examples/getting-started/installation.md +203 -0
  19. package/skill-packs/cocos2d/skills/cocos2d-x/examples/getting-started/quick-start.md +134 -0
  20. package/skill-packs/electron/pack.json +9 -0
  21. package/skill-packs/electron/skills/electron/LICENSE.txt +202 -0
  22. package/skill-packs/electron/skills/electron/SKILL.md +160 -0
  23. package/skill-packs/electron/skills/electron/api/app.md +83 -0
  24. package/skill-packs/electron/skills/electron/api/browser-window.md +84 -0
  25. package/skill-packs/electron/skills/electron/examples/advanced/packaging.md +140 -0
  26. package/skill-packs/electron/skills/electron/examples/api/browser-window.md +182 -0
  27. package/skill-packs/electron/skills/electron/examples/api/menu.md +187 -0
  28. package/skill-packs/electron/skills/electron/examples/getting-started/installation.md +88 -0
  29. package/skill-packs/electron/skills/electron/examples/getting-started/quick-start.md +104 -0
  30. package/skill-packs/electron/skills/electron/examples/processes/ipc-communication.md +140 -0
  31. package/skill-packs/electron/skills/electron/examples/processes/main-process.md +121 -0
  32. package/skill-packs/electron/skills/electron/templates/main-process.md +105 -0
  33. package/skill-packs/electron/skills/electron/templates/preload-script.md +84 -0
  34. package/skill-packs/electron/skills/electron-egg/LICENSE.txt +202 -0
  35. package/skill-packs/electron/skills/electron-egg/SKILL.md +154 -0
  36. package/skill-packs/electron/skills/electron-egg/api/config-api.md +62 -0
  37. package/skill-packs/electron/skills/electron-egg/api/ipc-api.md +55 -0
  38. package/skill-packs/electron/skills/electron-egg/api/main-api.md +54 -0
  39. package/skill-packs/electron/skills/electron-egg/api/renderer-api.md +62 -0
  40. package/skill-packs/electron/skills/electron-egg/api/window-api.md +64 -0
  41. package/skill-packs/electron/skills/electron-egg/examples/features/ipc-communication.md +84 -0
  42. package/skill-packs/electron/skills/electron-egg/examples/features/main-process.md +89 -0
  43. package/skill-packs/electron/skills/electron-egg/examples/features/renderer-process.md +74 -0
  44. package/skill-packs/electron/skills/electron-egg/examples/guide/build.md +77 -0
  45. package/skill-packs/electron/skills/electron-egg/examples/guide/configuration.md +88 -0
  46. package/skill-packs/electron/skills/electron-egg/examples/guide/installation.md +66 -0
  47. package/skill-packs/electron/skills/electron-egg/examples/guide/intro.md +47 -0
  48. package/skill-packs/electron/skills/electron-egg/examples/guide/project-structure.md +73 -0
  49. package/skill-packs/electron/skills/electron-egg/examples/guide/quick-start.md +78 -0
  50. package/skill-packs/electron/skills/electron-egg/templates/configuration.md +63 -0
  51. package/skill-packs/electron/skills/electron-egg/templates/installation.md +42 -0
  52. package/skill-packs/electron/skills/electron-egg/templates/project-setup.md +75 -0
  53. package/skill-packs/flutter/pack.json +9 -0
  54. package/skill-packs/flutter/skills/flutter/LICENSE.txt +202 -0
  55. package/skill-packs/flutter/skills/flutter/SKILL.md +127 -0
  56. package/skill-packs/flutter/skills/flutter-project-creater/LICENSE.txt +202 -0
  57. package/skill-packs/flutter/skills/flutter-project-creater/SKILL.md +106 -0
  58. package/skill-packs/threejs/pack.json +25 -0
  59. package/skill-packs/threejs/skills/README.md +95 -0
  60. package/skill-packs/threejs/skills/threejs-animation/SKILL.md +86 -0
  61. package/skill-packs/threejs/skills/threejs-animation/examples/workflow-mixer-action.md +20 -0
  62. package/skill-packs/threejs/skills/threejs-animation/references/official-sections.md +19 -0
  63. package/skill-packs/threejs/skills/threejs-audio/SKILL.md +112 -0
  64. package/skill-packs/threejs/skills/threejs-audio/examples/workflow-positional-audio.md +15 -0
  65. package/skill-packs/threejs/skills/threejs-audio/references/official-sections.md +16 -0
  66. package/skill-packs/threejs/skills/threejs-camera/SKILL.md +96 -0
  67. package/skill-packs/threejs/skills/threejs-camera/examples/workflow-perspective-resize.md +13 -0
  68. package/skill-packs/threejs/skills/threejs-controls/SKILL.md +101 -0
  69. package/skill-packs/threejs/skills/threejs-controls/examples/workflow-orbit-damping.md +15 -0
  70. package/skill-packs/threejs/skills/threejs-dev-setup/SKILL.md +102 -0
  71. package/skill-packs/threejs/skills/threejs-dev-setup/examples/workflow-scaffold.md +24 -0
  72. package/skill-packs/threejs/skills/threejs-geometries/SKILL.md +108 -0
  73. package/skill-packs/threejs/skills/threejs-geometries/examples/workflow-extrude-shape.md +13 -0
  74. package/skill-packs/threejs/skills/threejs-helpers/SKILL.md +103 -0
  75. package/skill-packs/threejs/skills/threejs-helpers/examples/workflow-light-camera-helpers.md +13 -0
  76. package/skill-packs/threejs/skills/threejs-lights/SKILL.md +103 -0
  77. package/skill-packs/threejs/skills/threejs-lights/examples/workflow-directional-shadow.md +17 -0
  78. package/skill-packs/threejs/skills/threejs-loaders/SKILL.md +89 -0
  79. package/skill-packs/threejs/skills/threejs-loaders/examples/workflow-gltf-draco.md +22 -0
  80. package/skill-packs/threejs/skills/threejs-loaders/references/official-sections.md +27 -0
  81. package/skill-packs/threejs/skills/threejs-materials/SKILL.md +102 -0
  82. package/skill-packs/threejs/skills/threejs-materials/examples/workflow-pbr-transparent.md +15 -0
  83. package/skill-packs/threejs/skills/threejs-math/SKILL.md +102 -0
  84. package/skill-packs/threejs/skills/threejs-math/examples/workflow-ray-aabb.md +11 -0
  85. package/skill-packs/threejs/skills/threejs-node-tsl/SKILL.md +83 -0
  86. package/skill-packs/threejs/skills/threejs-node-tsl/examples/workflow-tsl-entry.md +13 -0
  87. package/skill-packs/threejs/skills/threejs-node-tsl/references/official-links.md +8 -0
  88. package/skill-packs/threejs/skills/threejs-node-tsl/references/tsl-vs-classic.md +23 -0
  89. package/skill-packs/threejs/skills/threejs-objects/SKILL.md +111 -0
  90. package/skill-packs/threejs/skills/threejs-objects/examples/workflow-raycaster-pick.md +17 -0
  91. package/skill-packs/threejs/skills/threejs-postprocessing/SKILL.md +116 -0
  92. package/skill-packs/threejs/skills/threejs-postprocessing/examples/workflow-composer-bloom.md +15 -0
  93. package/skill-packs/threejs/skills/threejs-renderers/SKILL.md +91 -0
  94. package/skill-packs/threejs/skills/threejs-renderers/examples/workflow-renderer-resize.md +21 -0
  95. package/skill-packs/threejs/skills/threejs-renderers/references/official-sections.md +14 -0
  96. package/skill-packs/threejs/skills/threejs-scenes/SKILL.md +90 -0
  97. package/skill-packs/threejs/skills/threejs-scenes/examples/workflow-fog-background.md +13 -0
  98. package/skill-packs/threejs/skills/threejs-textures/SKILL.md +83 -0
  99. package/skill-packs/threejs/skills/threejs-textures/examples/workflow-pmrem-env.md +19 -0
  100. package/skill-packs/threejs/skills/threejs-webxr/SKILL.md +104 -0
  101. package/skill-packs/threejs/skills/threejs-webxr/examples/workflow-xr-button.md +15 -0
  102. package/skills/telegram-notify/SKILL.md +1 -0
  103. package/skills/trello-sync/SKILL.md +7 -0
  104. package/templates/project-identity/android.json +26 -1
  105. package/templates/project-identity/backend-nestjs.json +26 -1
  106. package/templates/project-identity/expo.json +26 -1
  107. package/templates/project-identity/ios.json +26 -1
  108. package/templates/project-identity/web-nextjs.json +26 -1
@@ -0,0 +1,291 @@
1
+ # Input(输入)处理指南
2
+
3
+ ## 官方文档
4
+
5
+ 参考官方文档:https://docs.cocos.com/cocos2d-x/v4/manual/zh/
6
+
7
+ ## 概述
8
+
9
+ Cocos2d-x 支持触摸、鼠标和键盘输入事件。
10
+
11
+ ## 触摸事件
12
+
13
+ ### 单点触摸
14
+
15
+ ```cpp
16
+ class TouchLayer : public Layer
17
+ {
18
+ public:
19
+ CREATE_FUNC(TouchLayer);
20
+ virtual bool init() override;
21
+
22
+ private:
23
+ bool onTouchBegan(Touch* touch, Event* event);
24
+ void onTouchMoved(Touch* touch, Event* event);
25
+ void onTouchEnded(Touch* touch, Event* event);
26
+ void onTouchCancelled(Touch* touch, Event* event);
27
+ };
28
+
29
+ bool TouchLayer::init()
30
+ {
31
+ if (!Layer::init())
32
+ {
33
+ return false;
34
+ }
35
+
36
+ // 创建触摸监听器
37
+ auto listener = EventListenerTouchOneByOne::create();
38
+ listener->setSwallowTouches(true);
39
+
40
+ // 绑定回调函数
41
+ listener->onTouchBegan = CC_CALLBACK_2(TouchLayer::onTouchBegan, this);
42
+ listener->onTouchMoved = CC_CALLBACK_2(TouchLayer::onTouchMoved, this);
43
+ listener->onTouchEnded = CC_CALLBACK_2(TouchLayer::onTouchEnded, this);
44
+ listener->onTouchCancelled = CC_CALLBACK_2(TouchLayer::onTouchCancelled, this);
45
+
46
+ // 注册监听器
47
+ _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
48
+
49
+ return true;
50
+ }
51
+
52
+ bool TouchLayer::onTouchBegan(Touch* touch, Event* event)
53
+ {
54
+ Vec2 location = touch->getLocation();
55
+ log("Touch began at: (%.2f, %.2f)", location.x, location.y);
56
+ return true; // 返回 true 表示要接收后续事件
57
+ }
58
+
59
+ void TouchLayer::onTouchMoved(Touch* touch, Event* event)
60
+ {
61
+ Vec2 location = touch->getLocation();
62
+ log("Touch moved to: (%.2f, %.2f)", location.x, location.y);
63
+ }
64
+
65
+ void TouchLayer::onTouchEnded(Touch* touch, Event* event)
66
+ {
67
+ Vec2 location = touch->getLocation();
68
+ log("Touch ended at: (%.2f, %.2f)", location.x, location.y);
69
+ }
70
+
71
+ void TouchLayer::onTouchCancelled(Touch* touch, Event* event)
72
+ {
73
+ log("Touch cancelled");
74
+ }
75
+ ```
76
+
77
+ ### 多点触摸
78
+
79
+ ```cpp
80
+ class MultiTouchLayer : public Layer
81
+ {
82
+ public:
83
+ CREATE_FUNC(MultiTouchLayer);
84
+ virtual bool init() override;
85
+
86
+ private:
87
+ void onTouchesBegan(const std::vector<Touch*>& touches, Event* event);
88
+ void onTouchesMoved(const std::vector<Touch*>& touches, Event* event);
89
+ void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
90
+ };
91
+
92
+ bool MultiTouchLayer::init()
93
+ {
94
+ if (!Layer::init())
95
+ {
96
+ return false;
97
+ }
98
+
99
+ auto listener = EventListenerTouchAllAtOnce::create();
100
+ listener->onTouchesBegan = CC_CALLBACK_2(MultiTouchLayer::onTouchesBegan, this);
101
+ listener->onTouchesMoved = CC_CALLBACK_2(MultiTouchLayer::onTouchesMoved, this);
102
+ listener->onTouchesEnded = CC_CALLBACK_2(MultiTouchLayer::onTouchesEnded, this);
103
+
104
+ _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
105
+
106
+ return true;
107
+ }
108
+
109
+ void MultiTouchLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
110
+ {
111
+ log("Touches began: %zu touches", touches.size());
112
+ for (auto touch : touches)
113
+ {
114
+ Vec2 location = touch->getLocation();
115
+ log(" Touch at: (%.2f, %.2f)", location.x, location.y);
116
+ }
117
+ }
118
+ ```
119
+
120
+ ## 鼠标事件
121
+
122
+ ```cpp
123
+ class MouseLayer : public Layer
124
+ {
125
+ public:
126
+ CREATE_FUNC(MouseLayer);
127
+ virtual bool init() override;
128
+
129
+ private:
130
+ void onMouseDown(Event* event);
131
+ void onMouseUp(Event* event);
132
+ void onMouseMove(Event* event);
133
+ void onMouseScroll(Event* event);
134
+ };
135
+
136
+ bool MouseLayer::init()
137
+ {
138
+ if (!Layer::init())
139
+ {
140
+ return false;
141
+ }
142
+
143
+ auto listener = EventListenerMouse::create();
144
+ listener->onMouseDown = CC_CALLBACK_1(MouseLayer::onMouseDown, this);
145
+ listener->onMouseUp = CC_CALLBACK_1(MouseLayer::onMouseUp, this);
146
+ listener->onMouseMove = CC_CALLBACK_1(MouseLayer::onMouseMove, this);
147
+ listener->onMouseScroll = CC_CALLBACK_1(MouseLayer::onMouseScroll, this);
148
+
149
+ _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
150
+
151
+ return true;
152
+ }
153
+
154
+ void MouseLayer::onMouseDown(Event* event)
155
+ {
156
+ EventMouse* mouseEvent = static_cast<EventMouse*>(event);
157
+ Vec2 location = mouseEvent->getLocationInView();
158
+ log("Mouse down at: (%.2f, %.2f)", location.x, location.y);
159
+ }
160
+
161
+ void MouseLayer::onMouseScroll(Event* event)
162
+ {
163
+ EventMouse* mouseEvent = static_cast<EventMouse*>(event);
164
+ float scrollY = mouseEvent->getScrollY();
165
+ log("Mouse scroll: %.2f", scrollY);
166
+ }
167
+ ```
168
+
169
+ ## 键盘事件
170
+
171
+ ```cpp
172
+ class KeyboardLayer : public Layer
173
+ {
174
+ public:
175
+ CREATE_FUNC(KeyboardLayer);
176
+ virtual bool init() override;
177
+
178
+ private:
179
+ void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event);
180
+ void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);
181
+ };
182
+
183
+ bool KeyboardLayer::init()
184
+ {
185
+ if (!Layer::init())
186
+ {
187
+ return false;
188
+ }
189
+
190
+ auto listener = EventListenerKeyboard::create();
191
+ listener->onKeyPressed = CC_CALLBACK_2(KeyboardLayer::onKeyPressed, this);
192
+ listener->onKeyReleased = CC_CALLBACK_2(KeyboardLayer::onKeyReleased, this);
193
+
194
+ _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
195
+
196
+ return true;
197
+ }
198
+
199
+ void KeyboardLayer::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event)
200
+ {
201
+ switch (keyCode)
202
+ {
203
+ case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
204
+ log("Left arrow pressed");
205
+ break;
206
+ case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
207
+ log("Right arrow pressed");
208
+ break;
209
+ case EventKeyboard::KeyCode::KEY_SPACE:
210
+ log("Space pressed");
211
+ break;
212
+ default:
213
+ break;
214
+ }
215
+ }
216
+ ```
217
+
218
+ ## 拖拽示例
219
+
220
+ ```cpp
221
+ class DragLayer : public Layer
222
+ {
223
+ public:
224
+ CREATE_FUNC(DragLayer);
225
+ virtual bool init() override;
226
+
227
+ private:
228
+ bool onTouchBegan(Touch* touch, Event* event);
229
+ void onTouchMoved(Touch* touch, Event* event);
230
+ void onTouchEnded(Touch* touch, Event* event);
231
+
232
+ Sprite* _draggedSprite;
233
+ bool _isDragging;
234
+ };
235
+
236
+ bool DragLayer::init()
237
+ {
238
+ if (!Layer::init())
239
+ {
240
+ return false;
241
+ }
242
+
243
+ // 创建可拖拽的精灵
244
+ _draggedSprite = Sprite::create("player.png");
245
+ _draggedSprite->setPosition(Vec2(400, 300));
246
+ this->addChild(_draggedSprite);
247
+
248
+ _isDragging = false;
249
+
250
+ auto listener = EventListenerTouchOneByOne::create();
251
+ listener->onTouchBegan = CC_CALLBACK_2(DragLayer::onTouchBegan, this);
252
+ listener->onTouchMoved = CC_CALLBACK_2(DragLayer::onTouchMoved, this);
253
+ listener->onTouchEnded = CC_CALLBACK_2(DragLayer::onTouchEnded, this);
254
+
255
+ _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
256
+
257
+ return true;
258
+ }
259
+
260
+ bool DragLayer::onTouchBegan(Touch* touch, Event* event)
261
+ {
262
+ Vec2 location = touch->getLocation();
263
+ Rect rect = _draggedSprite->getBoundingBox();
264
+
265
+ if (rect.containsPoint(location))
266
+ {
267
+ _isDragging = true;
268
+ return true;
269
+ }
270
+ return false;
271
+ }
272
+
273
+ void DragLayer::onTouchMoved(Touch* touch, Event* event)
274
+ {
275
+ if (_isDragging)
276
+ {
277
+ Vec2 location = touch->getLocation();
278
+ _draggedSprite->setPosition(location);
279
+ }
280
+ }
281
+
282
+ void DragLayer::onTouchEnded(Touch* touch, Event* event)
283
+ {
284
+ _isDragging = false;
285
+ }
286
+ ```
287
+
288
+ ## 参考资源
289
+
290
+ - **官方文档**: https://docs.cocos.com/cocos2d-x/v4/manual/zh/
291
+ - **Event 系统**: `examples/core/event.md`
@@ -0,0 +1,184 @@
1
+ # Label(标签)使用指南
2
+
3
+ ## 官方文档
4
+
5
+ 参考官方文档:https://docs.cocos.com/cocos2d-x/v4/manual/zh/
6
+
7
+ ## Instructions
8
+
9
+ Label 用于在游戏中显示文本。Cocos2d-x 支持多种标签类型:TTF、BMFont、CharMap。
10
+
11
+ ### Syntax
12
+
13
+ #### Label 类型
14
+
15
+ - `Label::createWithTTF()` - 使用 TTF 字体文件
16
+ - `Label::createWithBMFont()` - 使用 BMFont 位图字体
17
+ - `Label::createWithCharMap()` - 使用字符映射
18
+ - `Label::createWithSystemFont()` - 使用系统字体
19
+
20
+ #### Label 属性
21
+
22
+ - `setString()` - 设置文本内容
23
+ - `setFontSize()` - 设置字体大小
24
+ - `setTextColor()` - 设置文本颜色
25
+ - `setAlignment()` - 设置对齐方式
26
+ - `setDimensions()` - 设置文本区域大小
27
+
28
+ ### Example (TTF 标签)
29
+
30
+ ```cpp
31
+ // 使用 TTF 字体文件创建标签
32
+ auto label = Label::createWithTTF("Hello Cocos2d-x", "fonts/Marker Felt.ttf", 24);
33
+ label->setPosition(Vec2(400, 300));
34
+ label->setColor(Color3B::WHITE);
35
+ this->addChild(label);
36
+ ```
37
+
38
+ ### Example (系统字体标签)
39
+
40
+ ```cpp
41
+ // 使用系统字体创建标签
42
+ auto label = Label::createWithSystemFont("Hello World", "Arial", 24);
43
+ label->setPosition(Vec2(400, 300));
44
+ this->addChild(label);
45
+ ```
46
+
47
+ ### Example (BMFont 标签)
48
+
49
+ ```cpp
50
+ // 使用 BMFont 位图字体创建标签
51
+ auto label = Label::createWithBMFont("fonts/bitmap-font.fnt", "Hello");
52
+ label->setPosition(Vec2(400, 300));
53
+ this->addChild(label);
54
+ ```
55
+
56
+ ### Example (标签属性设置)
57
+
58
+ ```cpp
59
+ auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
60
+
61
+ // 设置文本
62
+ label->setString("New Text");
63
+
64
+ // 设置字体大小
65
+ label->setFontSize(32);
66
+
67
+ // 设置文本颜色
68
+ label->setTextColor(Color4B::RED);
69
+ label->setColor(Color3B::GREEN);
70
+
71
+ // 设置对齐方式
72
+ label->setAlignment(TextHAlignment::CENTER, TextVAlignment::CENTER);
73
+
74
+ // 设置文本区域(自动换行)
75
+ label->setDimensions(200, 100);
76
+ label->enableWrap(true);
77
+
78
+ // 设置行间距
79
+ label->setLineSpacing(10);
80
+
81
+ // 设置透明度
82
+ label->setOpacity(200);
83
+ ```
84
+
85
+ ### Example (多行文本)
86
+
87
+ ```cpp
88
+ auto label = Label::createWithTTF(
89
+ "This is a long text that will wrap to multiple lines",
90
+ "fonts/Marker Felt.ttf",
91
+ 20
92
+ );
93
+
94
+ // 设置文本区域大小(自动换行)
95
+ label->setDimensions(300, 0); // 宽度 300,高度自动
96
+ label->enableWrap(true);
97
+ label->setAlignment(TextHAlignment::LEFT, TextVAlignment::TOP);
98
+
99
+ label->setPosition(Vec2(400, 300));
100
+ this->addChild(label);
101
+ ```
102
+
103
+ ### Example (标签效果)
104
+
105
+ ```cpp
106
+ auto label = Label::createWithTTF("Hello", "fonts/Marker Felt.ttf", 48);
107
+
108
+ // 描边效果
109
+ label->enableOutline(Color4B::BLACK, 2);
110
+
111
+ // 阴影效果
112
+ label->enableShadow(Color4B::GRAY, Size(2, -2), 0);
113
+
114
+ // 发光效果
115
+ label->enableGlow(Color4B::YELLOW);
116
+
117
+ label->setPosition(Vec2(400, 300));
118
+ this->addChild(label);
119
+ ```
120
+
121
+ ### Example (动态更新文本)
122
+
123
+ ```cpp
124
+ class ScoreLabel : public Label
125
+ {
126
+ public:
127
+ CREATE_FUNC(ScoreLabel);
128
+ virtual bool init() override;
129
+
130
+ void updateScore(int score);
131
+
132
+ private:
133
+ int _score;
134
+ };
135
+
136
+ bool ScoreLabel::init()
137
+ {
138
+ if (!Label::initWithTTF("Score: 0", "fonts/Marker Felt.ttf", 24))
139
+ {
140
+ return false;
141
+ }
142
+
143
+ _score = 0;
144
+ this->setPosition(Vec2(100, 500));
145
+ this->setColor(Color3B::WHITE);
146
+
147
+ return true;
148
+ }
149
+
150
+ void ScoreLabel::updateScore(int score)
151
+ {
152
+ _score += score;
153
+ std::string text = StringUtils::format("Score: %d", _score);
154
+ this->setString(text);
155
+ }
156
+ ```
157
+
158
+ ### Example (富文本标签)
159
+
160
+ ```cpp
161
+ // 创建富文本标签
162
+ auto richText = RichText::create();
163
+ richText->setContentSize(Size(400, 100));
164
+
165
+ // 添加普通文本
166
+ auto text1 = RichElementText::create(1, Color3B::WHITE, 255, "Hello ", "fonts/Marker Felt.ttf", 24);
167
+ richText->pushBackElement(text1);
168
+
169
+ // 添加彩色文本
170
+ auto text2 = RichElementText::create(2, Color3B::RED, 255, "Cocos2d-x", "fonts/Marker Felt.ttf", 24);
171
+ richText->pushBackElement(text2);
172
+
173
+ // 添加图片
174
+ auto image = RichElementImage::create(3, Color3B::WHITE, 255, "icon.png");
175
+ richText->pushBackElement(image);
176
+
177
+ richText->setPosition(Vec2(400, 300));
178
+ this->addChild(richText);
179
+ ```
180
+
181
+ ## Reference
182
+
183
+ - **官方文档**: https://docs.cocos.com/cocos2d-x/v4/manual/zh/
184
+ - **Sprite 指南**: `examples/core/sprite.md`
@@ -0,0 +1,212 @@
1
+ # Node 和 Scene 基础
2
+
3
+ ## 官方文档
4
+
5
+ 参考官方文档:https://docs.cocos.com/cocos2d-x/v4/manual/zh/
6
+
7
+ ## Instructions
8
+
9
+ Node 是 Cocos2d-x 中所有显示对象的基础类,Scene 是场景图的根节点。理解 Node 和 Scene 的关系是使用 Cocos2d-x 的基础。
10
+
11
+ ### Syntax
12
+
13
+ #### Node 基础
14
+
15
+ - 所有显示对象都继承自 `Node`
16
+ - Node 支持位置、旋转、缩放、锚点等变换
17
+ - Node 可以添加子节点形成树结构
18
+ - Node 有生命周期方法:`onEnter()`, `onExit()`, `onEnterTransitionDidFinish()`, `onExitTransitionDidStart()`
19
+
20
+ #### Scene 基础
21
+
22
+ - Scene 继承自 Node,是场景图的根节点
23
+ - 通过 Director 管理场景切换
24
+ - 一个应用同时只能有一个运行的 Scene
25
+
26
+ ### Example (创建基本 Node)
27
+
28
+ ```cpp
29
+ #include "cocos2d.h"
30
+
31
+ USING_NS_CC;
32
+
33
+ // 创建一个简单的 Node
34
+ auto node = Node::create();
35
+ node->setPosition(Vec2(400, 300));
36
+ node->setRotation(45.0f);
37
+ node->setScale(1.5f);
38
+ node->setAnchorPoint(Vec2(0.5f, 0.5f));
39
+
40
+ // 添加到场景
41
+ scene->addChild(node);
42
+ ```
43
+
44
+ ### Example (Node 层次结构)
45
+
46
+ ```cpp
47
+ // 创建父节点
48
+ auto parent = Node::create();
49
+ parent->setPosition(Vec2(400, 300));
50
+
51
+ // 创建子节点
52
+ auto child1 = Sprite::create("sprite1.png");
53
+ child1->setPosition(Vec2(-50, 0)); // 相对于父节点
54
+ parent->addChild(child1);
55
+
56
+ auto child2 = Sprite::create("sprite2.png");
57
+ child2->setPosition(Vec2(50, 0)); // 相对于父节点
58
+ parent->addChild(child2);
59
+
60
+ // 添加到场景
61
+ scene->addChild(parent);
62
+ ```
63
+
64
+ ### Example (创建 Scene)
65
+
66
+ ```cpp
67
+ class HelloWorld : public Scene
68
+ {
69
+ public:
70
+ static Scene* createScene();
71
+ virtual bool init();
72
+ CREATE_FUNC(HelloWorld);
73
+ };
74
+
75
+ Scene* HelloWorld::createScene()
76
+ {
77
+ return HelloWorld::create();
78
+ }
79
+
80
+ bool HelloWorld::init()
81
+ {
82
+ if (!Scene::init())
83
+ {
84
+ return false;
85
+ }
86
+
87
+ auto visibleSize = Director::getInstance()->getVisibleSize();
88
+ Vec2 origin = Director::getInstance()->getVisibleOrigin();
89
+
90
+ // 添加内容到场景
91
+ auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
92
+ label->setPosition(Vec2(origin.x + visibleSize.width/2,
93
+ origin.y + visibleSize.height - label->getContentSize().height));
94
+ this->addChild(label, 1);
95
+
96
+ return true;
97
+ }
98
+ ```
99
+
100
+ ### Example (Node 生命周期)
101
+
102
+ ```cpp
103
+ class MyNode : public Node
104
+ {
105
+ public:
106
+ CREATE_FUNC(MyNode);
107
+ virtual bool init() override;
108
+ virtual void onEnter() override;
109
+ virtual void onEnterTransitionDidFinish() override;
110
+ virtual void onExit() override;
111
+ virtual void onExitTransitionDidStart() override;
112
+ };
113
+
114
+ bool MyNode::init()
115
+ {
116
+ if (!Node::init())
117
+ {
118
+ return false;
119
+ }
120
+ log("Node initialized");
121
+ return true;
122
+ }
123
+
124
+ void MyNode::onEnter()
125
+ {
126
+ Node::onEnter();
127
+ log("Node entered");
128
+ }
129
+
130
+ void MyNode::onEnterTransitionDidFinish()
131
+ {
132
+ Node::onEnterTransitionDidFinish();
133
+ log("Node transition finished");
134
+ }
135
+
136
+ void MyNode::onExit()
137
+ {
138
+ Node::onExit();
139
+ log("Node exited");
140
+ }
141
+
142
+ void MyNode::onExitTransitionDidStart()
143
+ {
144
+ Node::onExitTransitionDidStart();
145
+ log("Node transition started");
146
+ }
147
+ ```
148
+
149
+ ### Example (坐标系统)
150
+
151
+ ```cpp
152
+ // Cocos2d-x 使用 OpenGL 坐标系
153
+ // 原点在左下角,Y 轴向上
154
+
155
+ auto sprite = Sprite::create("player.png");
156
+
157
+ // 设置位置(世界坐标)
158
+ sprite->setPosition(Vec2(400, 300));
159
+
160
+ // 设置锚点(0.5, 0.5 表示中心)
161
+ sprite->setAnchorPoint(Vec2(0.5f, 0.5f));
162
+
163
+ // 获取世界坐标
164
+ Vec2 worldPos = sprite->getPosition();
165
+
166
+ // 转换为节点本地坐标
167
+ Vec2 localPos = sprite->convertToNodeSpace(worldPos);
168
+
169
+ // 转换为世界坐标
170
+ Vec2 worldPos2 = sprite->convertToWorldSpace(localPos);
171
+ ```
172
+
173
+ ### Example (Node 变换)
174
+
175
+ ```cpp
176
+ auto node = Node::create();
177
+
178
+ // 位置
179
+ node->setPosition(Vec2(400, 300));
180
+ node->setPositionX(400);
181
+ node->setPositionY(300);
182
+
183
+ // 旋转(角度)
184
+ node->setRotation(45.0f);
185
+ node->setRotationX(30.0f);
186
+ node->setRotationY(60.0f);
187
+
188
+ // 缩放
189
+ node->setScale(2.0f); // 统一缩放
190
+ node->setScaleX(1.5f); // X 轴缩放
191
+ node->setScaleY(0.8f); // Y 轴缩放
192
+
193
+ // 锚点
194
+ node->setAnchorPoint(Vec2(0.5f, 0.5f)); // 中心
195
+ node->setAnchorPoint(Vec2(0.0f, 0.0f)); // 左下角
196
+ node->setAnchorPoint(Vec2(1.0f, 1.0f)); // 右上角
197
+
198
+ // 可见性
199
+ node->setVisible(true);
200
+ node->setVisible(false);
201
+
202
+ // 透明度
203
+ node->setOpacity(255); // 完全不透明
204
+ node->setOpacity(128); // 半透明
205
+ node->setOpacity(0); // 完全透明
206
+ ```
207
+
208
+ ## Reference
209
+
210
+ - **官方文档**: https://docs.cocos.com/cocos2d-x/v4/manual/zh/
211
+ - **Scene 指南**: `examples/core/scene.md`
212
+ - **Sprite 指南**: `examples/core/sprite.md`