Cocos2d-js official documentation 19, Cocos2d-JS single file engine instructions, cocos2d-js Engine
This Guide describes how to use a single file engine for a Cocos2d-JS downloaded from an online download tool.
You may have downloaded one of the following three versions:
Cocos2d-JS Full Version: The Full Version engine contains all the features of the Cocos2d-JS engine and all the extensions, using this Version can help you discover the amazing creativity and possibilities of the Cocos2d-JS. You can view the list of features supported by the Cocos2d-JS on the official document homepage.
Cocos2d-JS Lite Version: The Lite Version contains only the core features of the Cocos2d-JS, which is stable, lightweight, and easy to use. It contains the following list of features:
- Canvas Renderer (WebGL not supported)
- Scenarios and layers
- Event manager
- Timer
- Genie and textures
- TTF text
- Sound
- Action
- Menus and menu items
Customized Version: If you select a custom Version engine, the engine script file contains all the features you selected.
Usage
.
Pay attention to the Script Loading time in the HelloWorld sample code:
window.onload = function(){ cc.game.onStart = function(){ //... }; cc.game.run("gameCanvas");};
As you can see,cc.game.onStart
Andcc.game.run
All in the onload function of window, because only in this case can you ensure that the cocos2d-js-v3.0.js has been loaded successfully, and you can use the Cocos2d-JS API in your user script. In our subsequent sections we will refer to another traditional workflow of Cocos2d-JS, which controls the loading sequence of scripts in the workflow, so there is no need to detect page loading.
You need to put these files on a local server or online server and access them through the server to see the correct results.
Help link
- Online API reference
- Download API Reference
- Document directory
- Github Repository
- Online Forum
- Online test example
About script Compression
You can use Google Closure Compiler to compress all js files into one file. Closure Compiler's advanced compression ratio is very high, even if you download a compression engine, you can also obtain a considerable compression ratio. The specific compression steps are as follows:
- Download the jar program file of Closure Compiler
- Configure build. xml according to your environment
- Run the ant command on the console
- Delete all js references on the page and introduce the packaged
game.min.js
Please note that you cannot write any js scripts on the html page. All js scripts must be packaged together; otherwise, errors may occur.
Note:
When you access the game page through the server, you will find an error message on the console: "Failed to load resource: the server responded with a status of 404 (Not Found )", promptproject.json
File not found
This is normal, not a problem. You can ignore it. Or you can add an emptyproject.json
File to avoid this error report.
Reprinted from: http://www.cocos2dx.net/post/241