Wow, I 've found many posts recently. I wrote some stuff this Friday. Now it's all over the street. My brother doesn't ask for fame or fortune. I feel pretty good. I'm also very happy to hear about Js ~ Haha. It was about to get off work. This article was written in a rush. Now it's better.
First understand SC-> getglobalobject ()... this student asked me .. you are not scientific... SC is a wool... that's what this guy said. you can't blame me. this is coming to work. sorry .... pu GE has always said to be happy with his mind. well. right. hope for this in a week .... okay. SC is the cocos2d-x package for us that single key .. students who have used it. and those who have read the source code will certainly know that cocos2d-x has a lot of single keys .. what is the director. XXX, right .. scriptingcore * SC = scriptingcore: getinstance ();
About the JS core class of the entire cocos2d-x is this stuff. scriptingcore. the root jsobject and JS context can be obtained through this operation. these two very important things. the following example is. get the variable X under the root node. the following things are very easy to understand.
1. js global variable operations.
1. Modify the value.
In this example,. js contains a global variable X. Now we get X to C ++. This is a string.
Jsval X; js_getproperty (SC-> getglobalcontext (), SC-> getglobalobject (), "X", & X); jsstring * PS = js_valuetostring (scriptingcore: getinstance () -> getglobalcontext (), x); jsstringwrapper Pw (PS); cclog (PW. get (). c_str ());
2. Get the value.
Another example is that there is a global variable X in. js. Now we use C ++ to set the value to helloworld!
Jsval x = c_string_to_jsval (SC-> getglobalcontext (), "helloworld! "); Js_setproperty (SC-> getglobalcontext (), SC-> getglobalobject ()," X ", & X );
To be continued... complicated arry and object.