Cocos2d-js official documentation 19, Cocos2d-JS single file engine instructions, cocos2d-js Engine

Source: Internet
Author: User

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.onStartAndcc.game.runAll 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:

  1. Download the jar program file of Closure Compiler
  2. Configure build. xml according to your environment
  3. Run the ant command on the console
  4. Delete all js references on the page and introduce the packagedgame.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.jsonFile not found

This is normal, not a problem. You can ignore it. Or you can add an emptyproject.jsonFile to avoid this error report.


Reprinted from: http://www.cocos2dx.net/post/241

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.