Cocos Creator basics (two)

Director type

cc.director is a singleton object that manages the logic flow of your game.
Since cc.director is a singleton, you don't need to call any constructor or create function.
The standard way to use it is by calling:
-cc.director.methodName();
It creates and processes the main window and manages when the scene is executed .

Scheduler type

Scheduler is the class responsible for triggering the callback function.
Generally, it is recommended to use cc.director.getScheduler() to get the system timer.
There are two different types of timers:

- update 定时器:每一帧都会触发。您可以自定义优先级。<br/>
- 自定义定时器:自定义定时器可以每一帧或者自定义的时间间隔触发。<br/>

schedule

Specify the callback function, call the object and other information to add a new timer.
If the paused value is true, the timing will not start until resume is called.
When the time interval reaches the specified value, the set callback function will be called.
If the interval value is 0, then the callback function will be called every frame, but if so, it is recommended to use scheduleUpdateForTarget instead.
If the callback function is already used by the timer, only the time interval parameter of the previous timer will be updated, and no new timer will be set.
The repeat value can make the timer trigger repeat + 1 time, and use cc.macro.REPEAT_FOREVER to make the timer trigger repeatedly.
The delay value specifies the delay time, and the timer will start timing after the specified time delay.

BlockInputEvents component reference

The BlockInputEvents component will intercept all input events (mouse and touch) in the bounding box of the node to which it belongs to prevent input from penetrating to lower-level nodes, and is generally used as the background of the upper-level UI.

Activate/deactivate node

The node is enabled by default, we can set its active state in the code, by setting the node activeproperties:

this.node.active = false;

Setting activeattributes and switch the active nodes in the editor, the closed state, the effect is the same. When a node is down, all its components will be disabled. At the same time, all its child nodes and components on the child nodes will also be disabled. Note that, when a child node is disabled, and will not change their activeproperties, so when the parent node reactivate when they will return to their original state.

In other words, activerepresents the fact that the node itself is active, and this node is currently whether can be activated depends on its parent. And if it is not in the current scene, it cannot be activated. We can read-only attribute on the node activeInHierarchyto determine whether it is currently active.

this.node.active = true;

If the node is in the original can be activated state, change activeis true it will immediately trigger activation:

  • Reactivate the node and all child nodes under the node whose active is true in the scene
  • The node will be on all the components and all child nodes are enabled, they are updateafter the method executes each frame
  • If these components have onEnablemethods that will be executed

this.node.active = false;

If the node originally had been activated, modified activeto false will immediately triggers a shutdown:

  • Hide this node and all child nodes under the node in the scene
  • The node and all child nodes on all components are disabled, i.e. not perform these components updatecode
  • If these components have onDisablemethods that will be executed

 

Guess you like

Origin blog.csdn.net/sun124608666/article/details/104615992