As more and more gaming companies enter the mobile field, the development cost is rising. The old-generation development language, represented by C ++, will face the impact of lua, js, and other scripting languages.
Over the past year or so, more and more companies are developing script-based solutions on mobile terminals. The open-source cocos2d community has long proposed the idea of using js to connect different branch versions. The underlying implementation method is the-x,-iphone, and html5 of each branch engine. js is used in the upper layer, so that projects can be easily exchanged among various engines.
From the perspective of game development, c ++ and js have their own advantages, and the combination of the two is unlimited. Not long ago, the cocos2d Community launched a joint release and took a key step. This series will be my learning cocos2d-x for js some experience.
Cocos2d-x for js is part of the cocos2d-x, he uses js as the script, the underlying use of c ++ to run, while improving the development speed, to ensure the execution efficiency.
First, we download the latest version of the cocos2d-x
Http://cocos2d-x.googlecode.com/files/cocos2d-2.1beta3-x-2.1.0.zip
This version contains several js game examples: CocosDragonJS, MoonWarriors, WatermelonWithMe
We do not use other ides for the moment, for cocos2d-x developers, the most ready-made tool at hand is. Open the project with vs2010 and find that there is neither js Code nor c ++ code. There is only one spidermonkey js interpreter and a win32 cocos2d-x shell.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1635415053-0.jpg "border =" 0 "alt =" "/>
Well, first we need to import the js source code. Unfortunately, the js source code of this project is not stored in the MoonWarriors directory, but in
Cocos2d-2.1beta3-x-2.1.0 \ samples \ TestJavascript \ cocos2d-js-tests \ games \ MoonWarriors in this folder
We will import the code to the MoonWarriors project.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1635414F4-1.jpg "border =" 0 "alt =" "/>
Okay, this directory structure is a bit painful. But I barely saw it.
However, we encountered another problem. In the js source code, the function of automatically completing the code is almost invalid. Tomato can only prompt the code in the current js file. The code in other files cannot be prompted. Especially js interfaces in the engine. This is really terrible.
I checked for half a day and found that there was no js version of code in the cocos2d-2.1beta3-x-2.1.0 engine. That is to say, they only use spidermonkey to bind the js interface to c ++. How can this be done? It cannot be used automatically without code.
Haha, as we said before, this is a joint release. That is to say, the js interfaces of each version should be consistent. That is to say, we can use the js Code of html5 version to help complete code prompts.
Go to the next html5 Engine
Http://cocos2d-x.googlecode.com/files/Cocos2d-html5-v2.1.zip
The code we want is 650 in these four folders) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1635413D9-2.jpg "border =" 0 "alt =" "/>
Import them to the project.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1635412102-3.jpg "border =" 0 "alt =" "/>
Then, we can open the source code of a project. It can be used automatically.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/163541M93-4.png "border =" 0 "alt =" "/>
Close the job.
This article is from the "Old G hut" blog, please be sure to keep this source http://4137613.blog.51cto.com/4127613/1113786