@leejungkiin/awkit 1.5.4 → 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.
- package/bin/awk.js +188 -8
- package/core/GEMINI.md +22 -14
- package/core/work-modes.json +45 -0
- package/package.json +1 -1
- package/skill-packs/cocos2d/pack.json +8 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/LICENSE.txt +8 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/SKILL.md +168 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/action.md +278 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/animation.md +220 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/event.md +133 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/input.md +291 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/label.md +184 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/node-scene.md +212 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/scene.md +228 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/sprite.md +206 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/core/texture.md +186 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/getting-started/about-engine.md +53 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/getting-started/installation.md +203 -0
- package/skill-packs/cocos2d/skills/cocos2d-x/examples/getting-started/quick-start.md +134 -0
- package/skill-packs/electron/pack.json +9 -0
- package/skill-packs/electron/skills/electron/LICENSE.txt +202 -0
- package/skill-packs/electron/skills/electron/SKILL.md +160 -0
- package/skill-packs/electron/skills/electron/api/app.md +83 -0
- package/skill-packs/electron/skills/electron/api/browser-window.md +84 -0
- package/skill-packs/electron/skills/electron/examples/advanced/packaging.md +140 -0
- package/skill-packs/electron/skills/electron/examples/api/browser-window.md +182 -0
- package/skill-packs/electron/skills/electron/examples/api/menu.md +187 -0
- package/skill-packs/electron/skills/electron/examples/getting-started/installation.md +88 -0
- package/skill-packs/electron/skills/electron/examples/getting-started/quick-start.md +104 -0
- package/skill-packs/electron/skills/electron/examples/processes/ipc-communication.md +140 -0
- package/skill-packs/electron/skills/electron/examples/processes/main-process.md +121 -0
- package/skill-packs/electron/skills/electron/templates/main-process.md +105 -0
- package/skill-packs/electron/skills/electron/templates/preload-script.md +84 -0
- package/skill-packs/electron/skills/electron-egg/LICENSE.txt +202 -0
- package/skill-packs/electron/skills/electron-egg/SKILL.md +154 -0
- package/skill-packs/electron/skills/electron-egg/api/config-api.md +62 -0
- package/skill-packs/electron/skills/electron-egg/api/ipc-api.md +55 -0
- package/skill-packs/electron/skills/electron-egg/api/main-api.md +54 -0
- package/skill-packs/electron/skills/electron-egg/api/renderer-api.md +62 -0
- package/skill-packs/electron/skills/electron-egg/api/window-api.md +64 -0
- package/skill-packs/electron/skills/electron-egg/examples/features/ipc-communication.md +84 -0
- package/skill-packs/electron/skills/electron-egg/examples/features/main-process.md +89 -0
- package/skill-packs/electron/skills/electron-egg/examples/features/renderer-process.md +74 -0
- package/skill-packs/electron/skills/electron-egg/examples/guide/build.md +77 -0
- package/skill-packs/electron/skills/electron-egg/examples/guide/configuration.md +88 -0
- package/skill-packs/electron/skills/electron-egg/examples/guide/installation.md +66 -0
- package/skill-packs/electron/skills/electron-egg/examples/guide/intro.md +47 -0
- package/skill-packs/electron/skills/electron-egg/examples/guide/project-structure.md +73 -0
- package/skill-packs/electron/skills/electron-egg/examples/guide/quick-start.md +78 -0
- package/skill-packs/electron/skills/electron-egg/templates/configuration.md +63 -0
- package/skill-packs/electron/skills/electron-egg/templates/installation.md +42 -0
- package/skill-packs/electron/skills/electron-egg/templates/project-setup.md +75 -0
- package/skill-packs/flutter/pack.json +9 -0
- package/skill-packs/flutter/skills/flutter/LICENSE.txt +202 -0
- package/skill-packs/flutter/skills/flutter/SKILL.md +127 -0
- package/skill-packs/flutter/skills/flutter-project-creater/LICENSE.txt +202 -0
- package/skill-packs/flutter/skills/flutter-project-creater/SKILL.md +106 -0
- package/skill-packs/threejs/pack.json +25 -0
- package/skill-packs/threejs/skills/README.md +95 -0
- package/skill-packs/threejs/skills/threejs-animation/SKILL.md +86 -0
- package/skill-packs/threejs/skills/threejs-animation/examples/workflow-mixer-action.md +20 -0
- package/skill-packs/threejs/skills/threejs-animation/references/official-sections.md +19 -0
- package/skill-packs/threejs/skills/threejs-audio/SKILL.md +112 -0
- package/skill-packs/threejs/skills/threejs-audio/examples/workflow-positional-audio.md +15 -0
- package/skill-packs/threejs/skills/threejs-audio/references/official-sections.md +16 -0
- package/skill-packs/threejs/skills/threejs-camera/SKILL.md +96 -0
- package/skill-packs/threejs/skills/threejs-camera/examples/workflow-perspective-resize.md +13 -0
- package/skill-packs/threejs/skills/threejs-controls/SKILL.md +101 -0
- package/skill-packs/threejs/skills/threejs-controls/examples/workflow-orbit-damping.md +15 -0
- package/skill-packs/threejs/skills/threejs-dev-setup/SKILL.md +102 -0
- package/skill-packs/threejs/skills/threejs-dev-setup/examples/workflow-scaffold.md +24 -0
- package/skill-packs/threejs/skills/threejs-geometries/SKILL.md +108 -0
- package/skill-packs/threejs/skills/threejs-geometries/examples/workflow-extrude-shape.md +13 -0
- package/skill-packs/threejs/skills/threejs-helpers/SKILL.md +103 -0
- package/skill-packs/threejs/skills/threejs-helpers/examples/workflow-light-camera-helpers.md +13 -0
- package/skill-packs/threejs/skills/threejs-lights/SKILL.md +103 -0
- package/skill-packs/threejs/skills/threejs-lights/examples/workflow-directional-shadow.md +17 -0
- package/skill-packs/threejs/skills/threejs-loaders/SKILL.md +89 -0
- package/skill-packs/threejs/skills/threejs-loaders/examples/workflow-gltf-draco.md +22 -0
- package/skill-packs/threejs/skills/threejs-loaders/references/official-sections.md +27 -0
- package/skill-packs/threejs/skills/threejs-materials/SKILL.md +102 -0
- package/skill-packs/threejs/skills/threejs-materials/examples/workflow-pbr-transparent.md +15 -0
- package/skill-packs/threejs/skills/threejs-math/SKILL.md +102 -0
- package/skill-packs/threejs/skills/threejs-math/examples/workflow-ray-aabb.md +11 -0
- package/skill-packs/threejs/skills/threejs-node-tsl/SKILL.md +83 -0
- package/skill-packs/threejs/skills/threejs-node-tsl/examples/workflow-tsl-entry.md +13 -0
- package/skill-packs/threejs/skills/threejs-node-tsl/references/official-links.md +8 -0
- package/skill-packs/threejs/skills/threejs-node-tsl/references/tsl-vs-classic.md +23 -0
- package/skill-packs/threejs/skills/threejs-objects/SKILL.md +111 -0
- package/skill-packs/threejs/skills/threejs-objects/examples/workflow-raycaster-pick.md +17 -0
- package/skill-packs/threejs/skills/threejs-postprocessing/SKILL.md +116 -0
- package/skill-packs/threejs/skills/threejs-postprocessing/examples/workflow-composer-bloom.md +15 -0
- package/skill-packs/threejs/skills/threejs-renderers/SKILL.md +91 -0
- package/skill-packs/threejs/skills/threejs-renderers/examples/workflow-renderer-resize.md +21 -0
- package/skill-packs/threejs/skills/threejs-renderers/references/official-sections.md +14 -0
- package/skill-packs/threejs/skills/threejs-scenes/SKILL.md +90 -0
- package/skill-packs/threejs/skills/threejs-scenes/examples/workflow-fog-background.md +13 -0
- package/skill-packs/threejs/skills/threejs-textures/SKILL.md +83 -0
- package/skill-packs/threejs/skills/threejs-textures/examples/workflow-pmrem-env.md +19 -0
- package/skill-packs/threejs/skills/threejs-webxr/SKILL.md +104 -0
- package/skill-packs/threejs/skills/threejs-webxr/examples/workflow-xr-button.md +15 -0
- package/skills/codex-conductor/SKILL.md +4 -4
- package/skills/gemini-conductor/SKILL.md +3 -2
- package/skills/telegram-notify/SKILL.md +1 -0
- package/skills/trello-sync/SKILL.md +7 -0
- package/templates/project-identity/android.json +26 -1
- package/templates/project-identity/backend-nestjs.json +26 -1
- package/templates/project-identity/expo.json +26 -1
- package/templates/project-identity/ios.json +26 -1
- package/templates/project-identity/web-nextjs.json +26 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Scene(场景)管理指南
|
|
2
|
+
|
|
3
|
+
## 官方文档
|
|
4
|
+
|
|
5
|
+
参考官方文档:https://docs.cocos.com/cocos2d-x/v4/manual/zh/
|
|
6
|
+
|
|
7
|
+
## 概述
|
|
8
|
+
|
|
9
|
+
Scene 是场景图的根节点,通过 Director 管理场景的切换和生命周期。
|
|
10
|
+
|
|
11
|
+
## 创建场景
|
|
12
|
+
|
|
13
|
+
### 基本场景
|
|
14
|
+
|
|
15
|
+
```cpp
|
|
16
|
+
class GameScene : public Scene
|
|
17
|
+
{
|
|
18
|
+
public:
|
|
19
|
+
static Scene* createScene();
|
|
20
|
+
virtual bool init();
|
|
21
|
+
CREATE_FUNC(GameScene);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
Scene* GameScene::createScene()
|
|
25
|
+
{
|
|
26
|
+
return GameScene::create();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
bool GameScene::init()
|
|
30
|
+
{
|
|
31
|
+
if (!Scene::init())
|
|
32
|
+
{
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 场景初始化代码
|
|
37
|
+
auto label = Label::createWithTTF("Game Scene", "fonts/Marker Felt.ttf", 24);
|
|
38
|
+
label->setPosition(Vec2(400, 300));
|
|
39
|
+
this->addChild(label);
|
|
40
|
+
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 场景切换
|
|
46
|
+
|
|
47
|
+
### 直接切换
|
|
48
|
+
|
|
49
|
+
```cpp
|
|
50
|
+
// 切换到新场景
|
|
51
|
+
auto newScene = GameScene::createScene();
|
|
52
|
+
Director::getInstance()->replaceScene(newScene);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 带过渡效果的切换
|
|
56
|
+
|
|
57
|
+
```cpp
|
|
58
|
+
// 淡入淡出过渡
|
|
59
|
+
auto transition = TransitionFade::create(1.0f, GameScene::createScene());
|
|
60
|
+
Director::getInstance()->replaceScene(transition);
|
|
61
|
+
|
|
62
|
+
// 翻页过渡
|
|
63
|
+
auto transition = TransitionPageTurn::create(1.0f, GameScene::createScene(), false);
|
|
64
|
+
Director::getInstance()->replaceScene(transition);
|
|
65
|
+
|
|
66
|
+
// 滑动过渡
|
|
67
|
+
auto transition = TransitionSlideInR::create(1.0f, GameScene::createScene());
|
|
68
|
+
Director::getInstance()->replaceScene(transition);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 场景生命周期
|
|
72
|
+
|
|
73
|
+
```cpp
|
|
74
|
+
class GameScene : public Scene
|
|
75
|
+
{
|
|
76
|
+
public:
|
|
77
|
+
virtual void onEnter() override;
|
|
78
|
+
virtual void onEnterTransitionDidFinish() override;
|
|
79
|
+
virtual void onExit() override;
|
|
80
|
+
virtual void onExitTransitionDidStart() override;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
void GameScene::onEnter()
|
|
84
|
+
{
|
|
85
|
+
Scene::onEnter();
|
|
86
|
+
log("Scene entered");
|
|
87
|
+
// 场景进入时的初始化
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void GameScene::onEnterTransitionDidFinish()
|
|
91
|
+
{
|
|
92
|
+
Scene::onEnterTransitionDidFinish();
|
|
93
|
+
log("Scene transition finished");
|
|
94
|
+
// 过渡完成后的操作
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
void GameScene::onExit()
|
|
98
|
+
{
|
|
99
|
+
Scene::onExit();
|
|
100
|
+
log("Scene exiting");
|
|
101
|
+
// 场景退出时的清理
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
void GameScene::onExitTransitionDidStart()
|
|
105
|
+
{
|
|
106
|
+
Scene::onExitTransitionDidStart();
|
|
107
|
+
log("Scene transition started");
|
|
108
|
+
// 过渡开始时的操作
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 场景层次结构
|
|
113
|
+
|
|
114
|
+
```cpp
|
|
115
|
+
bool GameScene::init()
|
|
116
|
+
{
|
|
117
|
+
if (!Scene::init())
|
|
118
|
+
{
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 背景层
|
|
123
|
+
auto backgroundLayer = Layer::create();
|
|
124
|
+
auto bgSprite = Sprite::create("background.png");
|
|
125
|
+
bgSprite->setPosition(Vec2(400, 300));
|
|
126
|
+
backgroundLayer->addChild(bgSprite);
|
|
127
|
+
this->addChild(backgroundLayer, 0);
|
|
128
|
+
|
|
129
|
+
// 游戏层
|
|
130
|
+
auto gameLayer = Layer::create();
|
|
131
|
+
// 添加游戏对象
|
|
132
|
+
this->addChild(gameLayer, 1);
|
|
133
|
+
|
|
134
|
+
// UI 层
|
|
135
|
+
auto uiLayer = Layer::create();
|
|
136
|
+
// 添加 UI 元素
|
|
137
|
+
this->addChild(uiLayer, 2);
|
|
138
|
+
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Director 使用
|
|
144
|
+
|
|
145
|
+
### 获取 Director 实例
|
|
146
|
+
|
|
147
|
+
```cpp
|
|
148
|
+
auto director = Director::getInstance();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 获取窗口信息
|
|
152
|
+
|
|
153
|
+
```cpp
|
|
154
|
+
auto director = Director::getInstance();
|
|
155
|
+
auto visibleSize = director->getVisibleSize();
|
|
156
|
+
Vec2 origin = director->getVisibleOrigin();
|
|
157
|
+
Vec2 center = Vec2(visibleSize.width/2 + origin.x,
|
|
158
|
+
visibleSize.height/2 + origin.y);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### 暂停和恢复
|
|
162
|
+
|
|
163
|
+
```cpp
|
|
164
|
+
// 暂停场景
|
|
165
|
+
Director::getInstance()->pause();
|
|
166
|
+
|
|
167
|
+
// 恢复场景
|
|
168
|
+
Director::getInstance()->resume();
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 完整示例
|
|
172
|
+
|
|
173
|
+
```cpp
|
|
174
|
+
class MenuScene : public Scene
|
|
175
|
+
{
|
|
176
|
+
public:
|
|
177
|
+
static Scene* createScene();
|
|
178
|
+
virtual bool init();
|
|
179
|
+
CREATE_FUNC(MenuScene);
|
|
180
|
+
|
|
181
|
+
private:
|
|
182
|
+
void onPlayButtonClicked(Ref* sender);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
bool MenuScene::init()
|
|
186
|
+
{
|
|
187
|
+
if (!Scene::init())
|
|
188
|
+
{
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
auto visibleSize = Director::getInstance()->getVisibleSize();
|
|
193
|
+
Vec2 origin = Director::getInstance()->getVisibleOrigin();
|
|
194
|
+
|
|
195
|
+
// 标题
|
|
196
|
+
auto title = Label::createWithTTF("My Game", "fonts/Marker Felt.ttf", 48);
|
|
197
|
+
title->setPosition(Vec2(origin.x + visibleSize.width/2,
|
|
198
|
+
origin.y + visibleSize.height - 100));
|
|
199
|
+
this->addChild(title, 1);
|
|
200
|
+
|
|
201
|
+
// 开始按钮
|
|
202
|
+
auto playButton = MenuItemImage::create(
|
|
203
|
+
"button_play.png",
|
|
204
|
+
"button_play_selected.png",
|
|
205
|
+
CC_CALLBACK_1(MenuScene::onPlayButtonClicked, this));
|
|
206
|
+
playButton->setPosition(Vec2(origin.x + visibleSize.width/2,
|
|
207
|
+
origin.y + visibleSize.height/2));
|
|
208
|
+
|
|
209
|
+
auto menu = Menu::create(playButton, nullptr);
|
|
210
|
+
menu->setPosition(Vec2::ZERO);
|
|
211
|
+
this->addChild(menu, 1);
|
|
212
|
+
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
void MenuScene::onPlayButtonClicked(Ref* sender)
|
|
217
|
+
{
|
|
218
|
+
auto gameScene = GameScene::createScene();
|
|
219
|
+
auto transition = TransitionFade::create(0.5f, gameScene);
|
|
220
|
+
Director::getInstance()->replaceScene(transition);
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## 参考资源
|
|
225
|
+
|
|
226
|
+
- **官方文档**: https://docs.cocos.com/cocos2d-x/v4/manual/zh/
|
|
227
|
+
- **Node 指南**: `examples/core/node-scene.md`
|
|
228
|
+
- **Director API**: `api/director.md`
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Sprite(精灵)使用指南
|
|
2
|
+
|
|
3
|
+
## 官方文档
|
|
4
|
+
|
|
5
|
+
参考官方文档:https://docs.cocos.com/cocos2d-x/v4/manual/zh/
|
|
6
|
+
|
|
7
|
+
## Instructions
|
|
8
|
+
|
|
9
|
+
Sprite 是 Cocos2d-x 中用于显示图片的基本节点类。Sprite 继承自 Node,可以显示纹理、支持动画、变换等操作。
|
|
10
|
+
|
|
11
|
+
### Syntax
|
|
12
|
+
|
|
13
|
+
#### 创建 Sprite
|
|
14
|
+
|
|
15
|
+
- `Sprite::create("filename.png")` - 从图片文件创建
|
|
16
|
+
- `Sprite::createWithTexture(texture)` - 从纹理创建
|
|
17
|
+
- `Sprite::createWithSpriteFrame(frame)` - 从精灵帧创建
|
|
18
|
+
- `Sprite::createWithSpriteFrameName("frame_name")` - 从精灵帧名称创建
|
|
19
|
+
- `Sprite::create("filename.png", Rect(x, y, width, height))` - 从纹理区域创建
|
|
20
|
+
|
|
21
|
+
### Example (从文件创建)
|
|
22
|
+
|
|
23
|
+
```cpp
|
|
24
|
+
// 从图片文件创建
|
|
25
|
+
auto sprite = Sprite::create("player.png");
|
|
26
|
+
this->addChild(sprite);
|
|
27
|
+
|
|
28
|
+
// 指定位置
|
|
29
|
+
sprite->setPosition(Vec2(100, 100));
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Example (从纹理创建)
|
|
33
|
+
|
|
34
|
+
```cpp
|
|
35
|
+
// 从纹理创建
|
|
36
|
+
auto texture = Director::getInstance()->getTextureCache()->addImage("player.png");
|
|
37
|
+
auto sprite = Sprite::createWithTexture(texture);
|
|
38
|
+
this->addChild(sprite);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Example (从纹理矩形创建)
|
|
42
|
+
|
|
43
|
+
```cpp
|
|
44
|
+
// 从纹理的某个区域创建(精灵表)
|
|
45
|
+
auto sprite = Sprite::create("spritesheet.png", Rect(0, 0, 32, 32));
|
|
46
|
+
this->addChild(sprite);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### Sprite 属性
|
|
50
|
+
|
|
51
|
+
- `setPosition(Vec2)` - 设置位置
|
|
52
|
+
- `setRotation(float)` - 设置旋转角度
|
|
53
|
+
- `setScale(float)` - 设置缩放
|
|
54
|
+
- `setAnchorPoint(Vec2)` - 设置锚点
|
|
55
|
+
- `setOpacity(GLubyte)` - 设置透明度
|
|
56
|
+
- `setColor(Color3B)` - 设置颜色
|
|
57
|
+
- `setFlippedX(bool)` - 水平翻转
|
|
58
|
+
- `setFlippedY(bool)` - 垂直翻转
|
|
59
|
+
|
|
60
|
+
### Example (位置和变换)
|
|
61
|
+
|
|
62
|
+
```cpp
|
|
63
|
+
auto sprite = Sprite::create("player.png");
|
|
64
|
+
|
|
65
|
+
// 设置位置
|
|
66
|
+
sprite->setPosition(Vec2(400, 300));
|
|
67
|
+
|
|
68
|
+
// 设置锚点(默认 0.5, 0.5)
|
|
69
|
+
sprite->setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
70
|
+
|
|
71
|
+
// 设置旋转
|
|
72
|
+
sprite->setRotation(45.0f);
|
|
73
|
+
|
|
74
|
+
// 设置缩放
|
|
75
|
+
sprite->setScale(2.0f); // 统一缩放
|
|
76
|
+
sprite->setScaleX(1.5f); // X 轴缩放
|
|
77
|
+
sprite->setScaleY(0.8f); // Y 轴缩放
|
|
78
|
+
|
|
79
|
+
// 设置透明度
|
|
80
|
+
sprite->setOpacity(128); // 0-255
|
|
81
|
+
|
|
82
|
+
// 设置颜色
|
|
83
|
+
sprite->setColor(Color3B::RED);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 翻转
|
|
87
|
+
|
|
88
|
+
```cpp
|
|
89
|
+
// 水平翻转
|
|
90
|
+
sprite->setFlippedX(true);
|
|
91
|
+
|
|
92
|
+
// 垂直翻转
|
|
93
|
+
sprite->setFlippedY(true);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Example (动画 Sprite - 使用 SpriteFrame)
|
|
97
|
+
|
|
98
|
+
```cpp
|
|
99
|
+
// 创建 SpriteFrame 缓存
|
|
100
|
+
auto cache = SpriteFrameCache::getInstance();
|
|
101
|
+
cache->addSpriteFramesWithFile("spritesheet.plist", "spritesheet.png");
|
|
102
|
+
|
|
103
|
+
// 从 SpriteFrame 创建
|
|
104
|
+
auto sprite = Sprite::createWithSpriteFrameName("player_idle_01.png");
|
|
105
|
+
this->addChild(sprite);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Example (帧动画)
|
|
109
|
+
|
|
110
|
+
```cpp
|
|
111
|
+
Vector<SpriteFrame*> frames;
|
|
112
|
+
for (int i = 1; i <= 4; i++)
|
|
113
|
+
{
|
|
114
|
+
std::string frameName = StringUtils::format("player_walk_%02d.png", i);
|
|
115
|
+
auto frame = cache->getSpriteFrameByName(frameName);
|
|
116
|
+
frames.pushBack(frame);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
auto animation = Animation::createWithSpriteFrames(frames, 0.1f);
|
|
120
|
+
auto animate = Animate::create(animation);
|
|
121
|
+
auto repeat = RepeatForever::create(animate);
|
|
122
|
+
|
|
123
|
+
sprite->runAction(repeat);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Example (完整示例)
|
|
127
|
+
|
|
128
|
+
```cpp
|
|
129
|
+
class GameScene : public Scene
|
|
130
|
+
{
|
|
131
|
+
public:
|
|
132
|
+
static Scene* createScene();
|
|
133
|
+
virtual bool init();
|
|
134
|
+
CREATE_FUNC(GameScene);
|
|
135
|
+
|
|
136
|
+
private:
|
|
137
|
+
Sprite* _player;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
bool GameScene::init()
|
|
141
|
+
{
|
|
142
|
+
if (!Scene::init())
|
|
143
|
+
{
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 创建玩家精灵
|
|
148
|
+
_player = Sprite::create("player.png");
|
|
149
|
+
_player->setPosition(Vec2(400, 300));
|
|
150
|
+
_player->setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
151
|
+
this->addChild(_player, 1);
|
|
152
|
+
|
|
153
|
+
// 添加动画
|
|
154
|
+
auto cache = SpriteFrameCache::getInstance();
|
|
155
|
+
cache->addSpriteFramesWithFile("player.plist", "player.png");
|
|
156
|
+
|
|
157
|
+
Vector<SpriteFrame*> frames;
|
|
158
|
+
for (int i = 1; i <= 4; i++)
|
|
159
|
+
{
|
|
160
|
+
auto frame = cache->getSpriteFrameByName(
|
|
161
|
+
StringUtils::format("player_walk_%02d.png", i));
|
|
162
|
+
frames.pushBack(frame);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
auto animation = Animation::createWithSpriteFrames(frames, 0.1f);
|
|
166
|
+
auto animate = Animate::create(animation);
|
|
167
|
+
auto repeat = RepeatForever::create(animate);
|
|
168
|
+
_player->runAction(repeat);
|
|
169
|
+
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Example (性能优化 - 使用 SpriteBatchNode)
|
|
175
|
+
|
|
176
|
+
```cpp
|
|
177
|
+
// 批量渲染相同纹理的精灵
|
|
178
|
+
auto batchNode = SpriteBatchNode::create("spritesheet.png", 100);
|
|
179
|
+
this->addChild(batchNode);
|
|
180
|
+
|
|
181
|
+
for (int i = 0; i < 50; i++)
|
|
182
|
+
{
|
|
183
|
+
auto sprite = Sprite::createWithTexture(batchNode->getTexture(),
|
|
184
|
+
Rect(i * 32, 0, 32, 32));
|
|
185
|
+
sprite->setPosition(Vec2(i * 50, 100));
|
|
186
|
+
batchNode->addChild(sprite);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Example (纹理缓存)
|
|
191
|
+
|
|
192
|
+
```cpp
|
|
193
|
+
// 预加载纹理
|
|
194
|
+
auto textureCache = Director::getInstance()->getTextureCache();
|
|
195
|
+
textureCache->addImage("player.png");
|
|
196
|
+
textureCache->addImage("enemy.png");
|
|
197
|
+
|
|
198
|
+
// 使用缓存的纹理
|
|
199
|
+
auto sprite = Sprite::create("player.png"); // 从缓存获取
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Reference
|
|
203
|
+
|
|
204
|
+
- **官方文档**: https://docs.cocos.com/cocos2d-x/v4/manual/zh/
|
|
205
|
+
- **Texture 指南**: `examples/core/texture.md`
|
|
206
|
+
- **Animation 指南**: `examples/core/animation.md`
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Texture(纹理)使用指南
|
|
2
|
+
|
|
3
|
+
## 官方文档
|
|
4
|
+
|
|
5
|
+
参考官方文档:https://docs.cocos.com/cocos2d-x/v4/manual/zh/
|
|
6
|
+
|
|
7
|
+
## Instructions
|
|
8
|
+
|
|
9
|
+
Texture 用于加载和管理图片资源。Cocos2d-x 使用 TextureCache 来缓存纹理,提高性能。
|
|
10
|
+
|
|
11
|
+
### Syntax
|
|
12
|
+
|
|
13
|
+
#### 纹理加载
|
|
14
|
+
|
|
15
|
+
- 使用 `Director::getInstance()->getTextureCache()` 获取纹理缓存
|
|
16
|
+
- `addImage()` 方法加载并缓存纹理
|
|
17
|
+
- `getTextureForKey()` 获取已缓存的纹理
|
|
18
|
+
- `removeTexture()` 移除纹理
|
|
19
|
+
- `removeAllTextures()` 清除所有纹理
|
|
20
|
+
|
|
21
|
+
#### 纹理属性
|
|
22
|
+
|
|
23
|
+
- `getPixelsWide()` - 获取纹理宽度
|
|
24
|
+
- `getPixelsHigh()` - 获取纹理高度
|
|
25
|
+
- `getContentSize()` - 获取内容大小
|
|
26
|
+
- `getPixelFormat()` - 获取像素格式
|
|
27
|
+
|
|
28
|
+
### Example (加载纹理)
|
|
29
|
+
|
|
30
|
+
```cpp
|
|
31
|
+
// 获取纹理缓存
|
|
32
|
+
auto textureCache = Director::getInstance()->getTextureCache();
|
|
33
|
+
|
|
34
|
+
// 加载纹理(会自动缓存)
|
|
35
|
+
auto texture = textureCache->addImage("player.png");
|
|
36
|
+
|
|
37
|
+
// 从纹理创建精灵
|
|
38
|
+
auto sprite = Sprite::createWithTexture(texture);
|
|
39
|
+
this->addChild(sprite);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Example (异步加载纹理)
|
|
43
|
+
|
|
44
|
+
```cpp
|
|
45
|
+
auto textureCache = Director::getInstance()->getTextureCache();
|
|
46
|
+
|
|
47
|
+
// 异步加载纹理
|
|
48
|
+
textureCache->addImageAsync("large_image.png", [this](Texture2D* texture) {
|
|
49
|
+
if (texture)
|
|
50
|
+
{
|
|
51
|
+
auto sprite = Sprite::createWithTexture(texture);
|
|
52
|
+
this->addChild(sprite);
|
|
53
|
+
log("Texture loaded successfully");
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
{
|
|
57
|
+
log("Failed to load texture");
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Example (纹理缓存管理)
|
|
63
|
+
|
|
64
|
+
```cpp
|
|
65
|
+
auto textureCache = Director::getInstance()->getTextureCache();
|
|
66
|
+
|
|
67
|
+
// 预加载纹理
|
|
68
|
+
textureCache->addImage("player.png");
|
|
69
|
+
textureCache->addImage("enemy.png");
|
|
70
|
+
textureCache->addImage("background.png");
|
|
71
|
+
|
|
72
|
+
// 获取已缓存的纹理
|
|
73
|
+
auto texture = textureCache->getTextureForKey("player.png");
|
|
74
|
+
if (texture)
|
|
75
|
+
{
|
|
76
|
+
auto sprite = Sprite::createWithTexture(texture);
|
|
77
|
+
this->addChild(sprite);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 移除单个纹理
|
|
81
|
+
textureCache->removeTexture(texture);
|
|
82
|
+
|
|
83
|
+
// 清除所有纹理(谨慎使用)
|
|
84
|
+
// textureCache->removeAllTextures();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Example (纹理信息)
|
|
88
|
+
|
|
89
|
+
```cpp
|
|
90
|
+
auto texture = Director::getInstance()->getTextureCache()->addImage("player.png");
|
|
91
|
+
|
|
92
|
+
// 获取纹理尺寸
|
|
93
|
+
int width = texture->getPixelsWide();
|
|
94
|
+
int height = texture->getPixelsHigh();
|
|
95
|
+
log("Texture size: %d x %d", width, height);
|
|
96
|
+
|
|
97
|
+
// 获取内容大小
|
|
98
|
+
Size contentSize = texture->getContentSize();
|
|
99
|
+
log("Content size: %.2f x %.2f", contentSize.width, contentSize.height);
|
|
100
|
+
|
|
101
|
+
// 获取像素格式
|
|
102
|
+
Texture2D::PixelFormat format = texture->getPixelFormat();
|
|
103
|
+
log("Pixel format: %d", format);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Example (从纹理区域创建精灵)
|
|
107
|
+
|
|
108
|
+
```cpp
|
|
109
|
+
// 加载纹理
|
|
110
|
+
auto texture = Director::getInstance()->getTextureCache()->addImage("spritesheet.png");
|
|
111
|
+
|
|
112
|
+
// 从纹理的某个区域创建精灵(精灵表)
|
|
113
|
+
Rect rect(0, 0, 32, 32); // x, y, width, height
|
|
114
|
+
auto sprite = Sprite::createWithTexture(texture, rect);
|
|
115
|
+
sprite->setPosition(Vec2(400, 300));
|
|
116
|
+
this->addChild(sprite);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Example (纹理预加载)
|
|
120
|
+
|
|
121
|
+
```cpp
|
|
122
|
+
class GameScene : public Scene
|
|
123
|
+
{
|
|
124
|
+
public:
|
|
125
|
+
static Scene* createScene();
|
|
126
|
+
virtual bool init();
|
|
127
|
+
CREATE_FUNC(GameScene);
|
|
128
|
+
|
|
129
|
+
private:
|
|
130
|
+
void preloadTextures();
|
|
131
|
+
int _loadedCount;
|
|
132
|
+
int _totalCount;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
void GameScene::preloadTextures()
|
|
136
|
+
{
|
|
137
|
+
auto textureCache = Director::getInstance()->getTextureCache();
|
|
138
|
+
|
|
139
|
+
std::vector<std::string> textures = {
|
|
140
|
+
"player.png",
|
|
141
|
+
"enemy.png",
|
|
142
|
+
"background.png",
|
|
143
|
+
"bullet.png"
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
_totalCount = textures.size();
|
|
147
|
+
_loadedCount = 0;
|
|
148
|
+
|
|
149
|
+
for (const auto& texturePath : textures)
|
|
150
|
+
{
|
|
151
|
+
textureCache->addImageAsync(texturePath, [this](Texture2D* texture) {
|
|
152
|
+
_loadedCount++;
|
|
153
|
+
log("Loaded %d/%d textures", _loadedCount, _totalCount);
|
|
154
|
+
|
|
155
|
+
if (_loadedCount == _totalCount)
|
|
156
|
+
{
|
|
157
|
+
log("All textures loaded!");
|
|
158
|
+
// 开始游戏
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Example (内存管理)
|
|
166
|
+
|
|
167
|
+
```cpp
|
|
168
|
+
// 在场景退出时清理不需要的纹理
|
|
169
|
+
void GameScene::onExit()
|
|
170
|
+
{
|
|
171
|
+
Scene::onExit();
|
|
172
|
+
|
|
173
|
+
// 移除游戏相关的纹理
|
|
174
|
+
auto textureCache = Director::getInstance()->getTextureCache();
|
|
175
|
+
textureCache->removeTextureForKey("player.png");
|
|
176
|
+
textureCache->removeTextureForKey("enemy.png");
|
|
177
|
+
|
|
178
|
+
// 注意:不要清除所有纹理,因为可能其他场景还在使用
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Reference
|
|
183
|
+
|
|
184
|
+
- **官方文档**: https://docs.cocos.com/cocos2d-x/v4/manual/zh/
|
|
185
|
+
- **Sprite 指南**: `examples/core/sprite.md`
|
|
186
|
+
- **资源管理**: `examples/core/resources.md`
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Cocos2d-x 引擎概述
|
|
2
|
+
|
|
3
|
+
## 官方文档
|
|
4
|
+
|
|
5
|
+
参考官方文档:https://docs.cocos.com/cocos2d-x/v4/manual/zh/
|
|
6
|
+
|
|
7
|
+
## 概述
|
|
8
|
+
|
|
9
|
+
Cocos2d-x 是一个开源的跨平台游戏开发框架,支持 C++ 开发,可以发布到多个平台。
|
|
10
|
+
|
|
11
|
+
## 引擎特性
|
|
12
|
+
|
|
13
|
+
### 跨平台支持
|
|
14
|
+
- **桌面平台**: Windows, macOS, Linux
|
|
15
|
+
- **移动平台**: Android, iOS
|
|
16
|
+
- **Web平台**: 通过 Cocos Creator 支持
|
|
17
|
+
|
|
18
|
+
### 核心功能
|
|
19
|
+
- 2D 图形渲染
|
|
20
|
+
- 精灵(Sprite)系统
|
|
21
|
+
- 动作(Action)系统
|
|
22
|
+
- 场景(Scene)管理
|
|
23
|
+
- 物理引擎集成(Box2D)
|
|
24
|
+
- 音频系统
|
|
25
|
+
- 粒子系统
|
|
26
|
+
- 动画系统
|
|
27
|
+
|
|
28
|
+
### 技术特点
|
|
29
|
+
- 基于 OpenGL ES 渲染
|
|
30
|
+
- 使用 C++ 开发
|
|
31
|
+
- CMake 构建系统
|
|
32
|
+
- 高性能渲染管线
|
|
33
|
+
- 支持自定义 Shader
|
|
34
|
+
|
|
35
|
+
## 版本信息
|
|
36
|
+
|
|
37
|
+
- **当前版本**: Cocos2d-x v4
|
|
38
|
+
- **主要语言**: C++
|
|
39
|
+
- **构建系统**: CMake
|
|
40
|
+
- **渲染后端**: OpenGL ES
|
|
41
|
+
|
|
42
|
+
## 适用场景
|
|
43
|
+
|
|
44
|
+
- 2D 游戏开发
|
|
45
|
+
- 跨平台游戏应用
|
|
46
|
+
- 教育类应用
|
|
47
|
+
- 工具类应用
|
|
48
|
+
|
|
49
|
+
## 参考资源
|
|
50
|
+
|
|
51
|
+
- **官方文档**: https://docs.cocos.com/cocos2d-x/v4/manual/zh/
|
|
52
|
+
- **GitHub**: https://github.com/cocos2d/cocos2d-x
|
|
53
|
+
- **社区论坛**: https://forum.cocos.org/
|