Skip to content

Commit cdf5d3d

Browse files
authored
完善部分文档 (cocos#1977)
* 完善部分文档 * 补充微信小游戏开启 WebGL 2.0 说明 * 完善 2D 渲染组件合批 * Fix error * Apply suggestions from code review
1 parent 1609984 commit cdf5d3d

File tree

15 files changed

+328
-191
lines changed

15 files changed

+328
-191
lines changed

en/editor/project/index.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,14 @@ Used to configure various parameters of physics, please refer to the [Physics Co
8686

8787
- **MAX_LABEL_CANVAS_POOL_SIZE**: set the maximum number of Canvas object pools used by the Label, and adjust it according to the number of Labels in the same scene of the project.
8888

89-
- **ENABLE_WEBGL_HIGHP_STRUCT_VALUES**: on the Android platform with WebGL backend, the internal variables of the structures defined in the fragment shader use **mediump** precision, which may lead to incorrect results for some data that requires high precision (such as position information). To avoid this problem, check this option (new in v3.4.1) and enable WebGL to calculate variables with **highp** precision.
89+
- **ENABLE_WEBGL_HIGHP_STRUCT_VALUES** (new in v3.4.1): on the Android platform with WebGL backend, the internal variables of the structures defined in the fragment shader use **mediump** precision, which may lead to incorrect results for some data that requires high precision (such as position information). To avoid this problem, check this option and enable WebGL to calculate variables with **highp** precision.
9090

9191
- If this option is enabled, use the `HIGHP_VALUE_STRUCT_DEFINE` macro in the fragment shader code to define structural variables, and use `HIGHP_VALUE_TO_STRUCT_DEFINED` and `HIGHP_VALUE_FROM_STRUCT_DEFINED` to assign values between structural and non-structural variables.
92+
9293
- For specific information and code on the above macro calls, please refer to [packing.chunk](https://github.com/cocos-creator/engine/blob/v3.4.1/editor/assets/chunks/packing.chunk#L40) for details.
9394

95+
- **BATCHER2D_MEM_INCREMENT** (new in v3.4.1): this option affects the maximum number of vertices in each MeshBuffer, the default value is 144KB, please refer to the [MeshBuffer Batch Description](../../ui-system/components/engine/ui-batch.md) documentation for the conversion relationship between the number and the value.
96+
9497
- **Custom Macro**: used to customize macro configurations, providing a macro tagging feature for current project scripts for easy visual configuration. Click the **+** button below to add a new macro configuration, hover over the added macro configuration and the **Delete** and **Modify** buttons will be displayed on the left side for deleting/renaming the current macro configuration respectively.
9598

9699
![macro](./index/custom-macro.png)

en/editor/project/index/macro.png

3.42 KB
Loading

en/editor/publish/publish-wechatgame.md

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ In addition, the game submission, review and release process of the **WeChat Min
4242

4343
### Build Options
4444

45+
![build](./publish-wechatgame/wechat-build.png)
46+
4547
| Options | Optional or not | Default | Explanation |
4648
| :-- | :-- | :-- | :-- |
4749
| **appid** | Required | `wx6ac3f5090a6b99c5` | The appid of the WeChat Mini Games, it will be written to `project.config.json` file.|
@@ -51,6 +53,7 @@ In addition, the game submission, review and release process of the **WeChat Min
5153
| **Orientation** | Required | `landscape` | Device orientation, it will be written to `game.json` file.|
5254
| **Separate Engine** | Optional | Empty | Whether to use WeChat Mini Games engine plugin, please refer to [WeChat Mini Games Engine Plugin Instructions](./wechatgame-plugin.md) for details. |
5355
| **Wasm 3D physics system (based on `ammo.js`)** | Optional | Enabled | This option is used to select whether to enable **Wasm**, which takes effect when using **bullet(ammo.js)** physics. Please refer to the **WebAssembly Support** section below for more details. |
56+
| **Whether to enabled WebGL2** (Experimental feature) | - | Forced Off | In order to allow WebGL 2.0 to be enabled on WeChat Mini Games in the future, we have added this option in **v3.4.1** to support to enable WebGL 2.0 following the configuration in the **Project Settings** panel, and to turn off to reduce the package by default.<br>If this option is set to **Consistent with project settings** and **WebGL 2.0** is checked in **Project Settings -> Feature Cropping**, it will be successfully enabled in the future if the WeChat environment supports WebGL 2.0. |
5457

5558
## Asset Management for WeChat Mini Game Environment
5659

Loading

en/engine/event/event-input.md

+117-66
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,77 @@
11
# Input Event System
22

3-
As mentioned in the previous document, `EventTarget` supports a complete set of event listening and emitting mechanisms. In Cocos Creator v3.4.0, `input` object is supported, which implements the event registering interface of `EventTarget`, and can register global system input events through this object. The original `systemEvent` object has been deprecated since v3.4.0, and the differences between `systemEvent` and `input` are as follows:
3+
As mentioned in the previous document, `EventTarget` supports a complete set of event listening and emitting mechanisms. In Cocos Creator v3.4.0, `input` object is supported, which implements the event registering interface of `EventTarget`, and can register global system input events through this object. The original `systemEvent` object has been deprecated since v3.4.0 and will be gradually removed in the future, we recommend using the `input` object as a replacement.
44

5-
- The declaration of touch event callback in `systemEvent` is `(touch: Touch, event: EventTouch) => void`
6-
- The declaration of touch event callback in `input` is `(event: EventTouch) => void`
5+
The differences between `systemEvent` and `input` are as follows:
76

8-
__Note__: in v3 4.0 there are also the following differences between the two objects:
9-
- The event listener of `systemEvent` will be intercepted by the event listener of the node.
10-
- `input` objects have higher priority than nodes and will not be intercepted.
11-
We have lowered the priority of 'input' in v3.4.1. Currently, there is no difference in priority between the two objects.
7+
- **Differences in type definitions**
128

13-
> __Note__: the `systemEvent` object is no longer recommended and will be phased out in the future, we recommend using the `input` object as a replacement.
9+
- The declaration of touch event callback in `systemEvent` is `(touch: Touch, event: EventTouch) => void`
1410

15-
In this section, the `global input events` of __Cocos Creator__ will be introduced.
11+
- The declaration of touch event callback in `input` is `(event: EventTouch) => void`
1612

17-
`Global input events` are irrelevant with the node hierarchy, so they are dispatched globally by `input`, currently supported:
13+
- **Differences in priority**
14+
15+
- The event listener of `systemEvent` will be intercepted by the event listener of the node.
16+
17+
- `input` objects have higher priority than nodes and will not be intercepted.
18+
19+
> __Note__: we lowered the priority of `input` in **v3.4.1**, so there is no difference in priority between the two objects since v3.4.1.
20+
21+
---
22+
23+
In this section, the handling of global input events in Cocos Creator will be introduced.
24+
25+
**Global input events** are irrelevant with the node hierarchy, so they are dispatched globally by `input`, currently supported:
1826

1927
- Mouse
2028
- Touch
21-
- Keyboard
29+
- Keyboard
2230
- DeviceMotion
2331

2432
## How to define the input events
2533

26-
Use `input.on(type, callback, target)` to register global input event listeners.
34+
Use `input.on(type, callback, target)` to register global input event listeners. Event types included:
2735

28-
Event types included:
29-
30-
1. `Input.EventType.MOUSE_DOWN`, `Input.EventType.MOUSE_MOVE`, `Input.EventType.MOUSE_UP`, `Input.EventType.MOUSE_WHEEL`
31-
2. `Input.EventType.TOUCH_START`, `Input.EventType.TOUCH_MOVE`, `Input.EventType.TOUCH_CANCEL`, `Input.EventType.TOUCH_END`
32-
3. `Input.EventType.KEY_DOWN`, `Input.EventType.KEY_PRESSING`, `Input.EventType.KEY_UP`
33-
4. `Input.EventType.DEVICEMOTION`
36+
| Input Event | `type` |
37+
| :----- | :---------- |
38+
| Mouse Event | `Input.EventType.MOUSE_DOWN`<br>`Input.EventType.MOUSE_MOVE`<br>`Input.EventType.MOUSE_UP`<br>`Input.EventType.MOUSE_WHEEL` |
39+
| Touch Event | `Input.EventType.TOUCH_START`<br>`Input.EventType.TOUCH_MOVE`<br>`Input.EventType.TOUCH_END`<br>`Input.EventType.TOUCH_CANCEL` |
40+
| Keyboard Event | `Input.EventType.KEY_DOWN` (keyboard pressed)<br>`Input.EventType.KEY_PRESSING` (keyboard continuously pressed)<br>`Input.EventType.KEY_UP` (keyboard release) |
41+
| DeviceMotion Event | `Input.EventType.DEVICEMOTION` |
3442

3543
### Pointer Events
3644

3745
Pointer events include mouse and touch events.
3846

39-
- Event Listener Types:
40-
- `Input.EventType.MOUSE_DOWN`, `Input.EventType.MOUSE_MOVE`, `Input.EventType.MOUSE_UP`, `Input.EventType.MOUSE_WHEEL`
41-
- `Input.EventType.TOUCH_START`, `Input.EventType.TOUCH_MOVE`, `Input.EventType.TOUCH_CANCEL`, `Input.EventType.TOUCH_END`
42-
- Callback Function:
43-
- Custom Function: callback(event);
44-
- Callback Parameter:
47+
- Event listener types
48+
49+
- Mouse event listening
50+
51+
- `Input.EventType.MOUSE_DOWN`
52+
53+
- `Input.EventType.MOUSE_MOVE`
54+
55+
- `Input.EventType.MOUSE_UP`
56+
57+
- `Input.EventType.MOUSE_WHEEL`
58+
59+
- Touch event listening
60+
61+
- `Input.EventType.TOUCH_START`
62+
63+
- `Input.EventType.TOUCH_MOVE`
64+
65+
- `Input.EventType.TOUCH_CANCEL`
66+
67+
- `Input.EventType.TOUCH_END`
68+
69+
- Callback function after event triggering
70+
71+
- Custom callback function: `callback(event);`
72+
73+
- Callback parameter
74+
4575
- [EventMouse](__APIDOC__/en/#/docs/3.4/en/cocos-input-types-event/Class/EventMouse) or [EventTouch](__APIDOC__/en/#/docs/3.4/en/cocos-input-types-event/Class/EventTouch)
4676

4777
Examples of the use of pointer events are as follows:
@@ -69,12 +99,24 @@ export class Example extends Component {
6999

70100
### Keyboard events
71101

72-
- Event Listener Types: `Input.EventType.KEY_DOWN``Input.EventType.KEY_PRESSING` and `Input.EventType.KEY_UP`
73-
- Callback Function:
74-
- Custom Function: callback(event);
75-
- Callback Parameter:
102+
- Event listener types
103+
104+
- `Input.EventType.KEY_DOWN`
105+
106+
- `Input.EventType.KEY_PRESSING`
107+
108+
- `Input.EventType.KEY_UP`
109+
110+
- Callback function after event triggering
111+
112+
- Custom Function: `callback(event);`
113+
114+
- Callback parameter
115+
76116
- [EventKeyboard](__APIDOC__/en/#/docs/3.4/en/event/Class/EventKeyboard)
77117

118+
Examples of the use of keyboard events are as follows:
119+
78120
```ts
79121
import { _decorator, Component, input, Input, EventKeyboard, KeyCode } from 'cc';
80122
const { ccclass } = _decorator;
@@ -111,11 +153,19 @@ export class Example extends Component {
111153

112154
### Device Motion
113155

114-
- Type: `Input.EventType.DEVICEMOTION`
115-
- Callback:
116-
- Custom Function: `callback(event);`;
117-
- Callback parameter:
118-
- [EventAcceleration](__APIDOC__/en/#/docs/3.4/en/cocos-input-types-event/Class/EventAcceleration)
156+
- Event listener type
157+
158+
- `Input.EventType.DEVICEMOTION`
159+
160+
- Callback function after event triggering
161+
162+
- Custom callback function: `callback(event);`
163+
164+
- Callback parameter
165+
166+
- [EventAcceleration](__APIDOC__/en/#/docs/3.4/en/cocos-input-types-event/Class/EventAcceleration)
167+
168+
Examples of the use of DeviceMotion events are as follows:
119169

120170
```ts
121171
import { _decorator, Component, input, Input, log } from 'cc';
@@ -138,54 +188,55 @@ export class Example extends Component {
138188
}
139189
```
140190

141-
Please review the [test-cases-3d](https://github.com/cocos-creator/test-cases-3d/tree/v3.4/assets/cases/event) (This includes the keyboard, accelerometer, single touch, multi-touch examples).
191+
The specific usage can be found in the example [event](https://github.com/cocos-creator/test-cases-3d/tree/v3.4/assets/cases/event), which contains the implementation of keyboard, accelerometer, single-touch, multi-touch and other functions.
142192

143193
## Touch detection for 3D objects
144194

145195
The touch detection for 3D objects and 2D UI nodes is different:
146196

147-
- 2D UI nodes only need the size information provided by the `UITransform` component and the position information of the node to do the touch detection. For details, please refer to [Node Event System](event-node.ts).
197+
- 2D UI nodes only need the size information provided by the `UITransform` component and the position information of the node to do the touch detection. For details, please refer to [Node Event System](event-node.md).
198+
148199
- The touch detection for 3D objects needs to be implemented by ray cast. The specific method is to generate a ray from the rendering camera of the 3D object to the screen coordinates of the touch point to determine whether the ray hits the object that was detected. The specific code implementation is as follows:
149200

150-
```ts
151-
import { _decorator, Component, Node, Camera, geometry, input, Input, EventTouch, PhysicsSystem } from 'cc';
152-
const { ccclass, property } = _decorator;
201+
```ts
202+
import { _decorator, Component, Node, Camera, geometry, input, Input, EventTouch, PhysicsSystem } from 'cc';
203+
const { ccclass, property } = _decorator;
153204

154-
@ccclass("Example")
155-
export class Example extends Component {
205+
@ccclass("Example")
206+
export class Example extends Component {
156207

157-
// Specify the camera rendering the target node.
158-
@property(Camera)
159-
readonly cameraCom!: Camera;
208+
// Specify the camera rendering the target node.
209+
@property(Camera)
210+
readonly cameraCom!: Camera;
160211

161-
@property(Node)
162-
public targetNode!: Node
212+
@property(Node)
213+
public targetNode!: Node
163214

164-
private _ray: geometry.Ray = new geometry.Ray();
215+
private _ray: geometry.Ray = new geometry.Ray();
165216

166-
onEnable () {
167-
input.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
168-
}
217+
onEnable () {
218+
input.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
219+
}
169220

170-
onDisable () {
171-
input.off(Input.EventType.TOUCH_START, this.onTouchStart, this);
172-
}
221+
onDisable () {
222+
input.off(Input.EventType.TOUCH_START, this.onTouchStart, this);
223+
}
173224

174-
onTouchStart(event: EventTouch) {
175-
const touch = event.touch!;
176-
this.cameraCom.screenPointToRay(touch.getLocationX(), touch.getLocationY(), this._ray);
177-
if (PhysicsSystem.instance.raycast(this._ray)) {
178-
const raycastResults = PhysicsSystem.instance.raycastResults;
179-
for (let i = 0; i < raycastResults.length; i++) {
180-
const item = raycastResults[i];
181-
if (item.collider.node == this.targetNode) {
182-
console.log('raycast hit the target node !');
183-
break;
225+
onTouchStart(event: EventTouch) {
226+
const touch = event.touch!;
227+
this.cameraCom.screenPointToRay(touch.getLocationX(), touch.getLocationY(), this._ray);
228+
if (PhysicsSystem.instance.raycast(this._ray)) {
229+
const raycastResults = PhysicsSystem.instance.raycastResults;
230+
for (let i = 0; i < raycastResults.length; i++) {
231+
const item = raycastResults[i];
232+
if (item.collider.node == this.targetNode) {
233+
console.log('raycast hit the target node !');
234+
break;
235+
}
184236
}
237+
} else {
238+
console.log('raycast does not hit the target node !');
185239
}
186-
} else {
187-
console.log('raycast does not hit the target node !');
188240
}
189241
}
190-
}
191-
```
242+
```

en/engine/event/event-node.md

+4-16
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Touch events support the event bubbling on the node tree, take the pictures belo
120120

121121
In the scene shown in the picture, suppose node A has a child node B which has a child node C. The developer sets the touch event listeners for all these three nodes (each node has a touch event listener in examples below by default).
122122

123-
When the mouse or finger was applied in the node C region, the event will be triggered at node C first and the node C listener will receive the event (this is the target phase). Then the node C will pass this event to its parent node, so the node B listener will receive this event. Similarly the node B will also pass the event to its parent node A. This is a basic event bubbling phase.
123+
When the mouse or finger was applied in the node C region, the event will be triggered at node C first and the node C listener will receive the event (this is the target phase). Then the node C will pass this event to its parent node, so the node B listener will receive this event. Similarly the node B will also pass the event to its parent node A. This is a basic event bubbling phase.
124124

125125
> __Note__: it needs to be emphasized that there is no hit test in parent nodes in the bubbling phase, which means that nodes A and B can receive touch events even though the touch location is out of their node area.
126126
@@ -132,9 +132,9 @@ Suppose the node B and C in the picture above are brother nodes, while C partly
132132

133133
At the same time, if C has a parent node, it will also pass the touch event to its parent node through the event bubble mechanism.
134134

135-
In v3.4.0, the ability of event penetrating dispatch is supported. In this example, if the event needs to be dispatched to node B, the event can be prevented from being swallowed by node C by calling `event.preventSwallow = true`.
135+
In v3.4.0, the ability of event penetrating dispatch is supported. In this example, if the event needs to be dispatched to node B, the event can be prevented from being swallowed by node C by calling `event.preventSwallow = true`.
136136

137-
> __Note__: the event penetrating dispatch reduces the efficiency of event dispatch, please use it with caution.
137+
> __Note__: the event penetrating dispatch reduces the efficiency of event dispatch, please use it with caution.
138138
139139
### Point of Contact Attribution for Different Canvas
140140

@@ -158,7 +158,7 @@ Only touch or mouse events can be registered in the capturing phase, while the o
158158

159159
### Event Interception
160160

161-
Normal events are dispensed as described above. However, if the node has components such as `Button`, `Toggle` or `BlockInputEvents` on it, it will stop event bubbling.
161+
Normal events are dispensed as described above. However, if the node has components such as `Button`, `Toggle` or `BlockInputEvents` on it, it will stop event bubbling.
162162

163163
Look at the picture below. There are two buttons, priority 1 for Canvas0 and priority 2 for Canvas1. Click on the intersection of the two buttons, which is the blue area in the picture, it appears that button priority 2 received the contact event successfully, while button priority 1 did not. <br>That's because according to the event reception rules above, button priority 2 receives contact events first and intercepts them (`event.propagationStopped = true`) to prevent event penetration. If the node is a non-button node, events can also be intercepted by adding the `BlockInputEvents` component to prevent penetration.
164164

@@ -243,15 +243,3 @@ Resume node system events
243243
// Example
244244
this.node.resumeSystemEvents();
245245
```
246-
247-
248-
249-
250-
251-
252-
253-
254-
255-
256-
257-

0 commit comments

Comments
 (0)