Home > other >  Using CocosCreator some basic usage of the script (1)
Using CocosCreator some basic usage of the script (1)

Time:09-16

I first learn CocosCreator, learned some basic knowledge, I'll use these, I can think of knowledge into an article for as much as I do of the new study together, everybody bosses when this is just a simple article,

 output statements: 
Console. The log (output), using the above output statements for a long time later, after I change again the statement
Use more simple output statements:
Cc. The log (output);


 find nodes method: 
Cc. Find (the root node: canvas/child nodes);
If you want to find the object is under the root node, the root node is the canvas, otherwise, the root node in the editor for yourself out of the other node name


 for the current node component method: 
This. Node. GetComponent (component type);
The types of components must be capitalized, such as cc. Label, cc. Sprite components such as


 for the parent node of the current node method: 
The current mount script node's parent:
Let parentNode=this. Node. The parent;


 for all child nodes of the current node method: 
Let.childnodes=this. Node. The children;
To obtain a child node of the current node (need to know the name of the child nodes, and name in single quotes or double quotes) :
Let childNode=this. Node. GetChildByName (" the name of the child nodes of the current node ");


 prefabricated body loading method: 
Cc. Loader. LoadRes (parameters parameters 1, 2, 3);
Parameter 1: to load the precast body directory (need to put the precast body in the resources folder)
Parameter 2: load prefabricated body type (type must be capitalized!!! )
Parameter 3: method of the callback function (call wrong return parameters, when the call is successful return parameters) {}
Parameter 3 code example:
Function (err, a) {
If (err) {
Cc. The log (err);
}
Cc. The log (a);
})


The use of
 audio: 
The method of playing music:
Cc. AudioEngine. PlayMusic (parameters 1, 2);
Parameter 1: audio resources
Parameter 2: whether looping audio (Boolean)
Set up play the volume of the music:
Cc. AudioEngine. SetMusicVolume parameters (1);
Parameter 1: volume value (0-1)
Stop music playing method:
Cc. AudioEngine. StopMusic ();


 
Animation of the slow system:
Cc. Tween (slow moving nodes)
To (slow time,} {to achieve animation)
.start();
Example:
Cc. Tween (enclosing node)
To (2, {x: 100, y: 100, scale: 3, Angle: 720})
.start();


Above is the knowledge I learned some CocosCreator, hope can help to you,
  • Related