This article describes how to use JavaScript syntax in the cocos2d-html5 engine. As for the js basics and more in-depth syntax, Please study it on your own!
1. First, we will introduce how to define functions in the following format:
| 1234 |
//Function Definitionfunction_test:function(pro1,pro2){}, |
Definition form: method name colon function (parameter ...) {... },
Note that:
1. When defining a function, the final ending symbol ",", in the form of a comma!
2. To call a function, put it in the declarative function body!
2. Local variables, definition and use of member variables
| 12345678910111213141516171819 |
var Helloworld =cc.Layer.extend({ //Member variablesint_prog:10,int_array:[],str_prog:"hello",enum_prog:{tag1:10,tag2:20},//Function Definitionfunction_test:function(pro1,pro2){this.init_prog =20;//Local variablevar int_prog_jb ="Local functions";//Print windowalert(this.init_prog);},}); |
Definition form of member variables: variable name colon initialization,
Note:
1. Define the member variables with the same comma.
2. Use this to access all member variables.
The definition of local variables is simple. (Note that the semicolon ends ";")
Alert ("content"); The content is displayed in a pop-up window.
This article is from the "Li huaming Himi" blog, please be sure to keep this source http://xiaominghimi.blog.51cto.com/2614927/1284387