Giter Site home page Giter Site logo

jiangzhonghui / js-multiplatform-game02 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from osuka/js-multiplatform-game02

0.0 1.0 0.0 97.48 MB

A javascript-based game for iOS, Android and HTML5 using cocos2d-js 3.0 & cocos2d-x 3.1

JavaScript 25.34% Makefile 0.16% C++ 62.40% C 7.13% Java 1.05% Python 0.14% Shell 0.03% PowerShell 0.11% Objective-C 2.07% Objective-C++ 1.44% C# 0.13%

js-multiplatform-game02's Introduction

A Javascript-based base game for iOS, Android and HTML5 devices

Summary

This is a relatively simple game made using open source technologies and with almost all of the logic in cross-platform Javascript.

This is an updated version of js-multiplatform-game01 to work with cocos2d-x-3.1 and cocos2d-js-3.0-beta.

I'm using:

  • npm, browserify for dependency management
  • grunt for building
  • cocos2d-x (3.1) and cocos2d-js (3.0-beta) as the game engine
  • chipmunk as the physics engine
  • Inkscape for graphics

Requirements:

  • node 0.10.24 to trigger everything else
  • A version of python is currently needed to run the Android build script (plans to migrate it to node).

You are encouraged to reuse this in any way you want and to give feedback and report errors or suggestions using the github page.

Installation

  • Make sure you have node installed. If not, get it from the nodejs website.

  • Install grunt, the tool used for building the game. Run npm install -g grunt-cli to do so.

  • Get a copy of the repository using git.

git clone https://github.com/osuka/js-multiplatform-game02
  • Use the node package manager to download all the external libraries.
npm install -g grunt-cli
npm install

You are almost done!

Launching the HTML5 version

You can run the HTML5 version in your computer executing the following:

grunt server

(then navigate to http://localhost:9000)

Launching the XCode (iOS, Mac) version

  • Build the game using grunt build:ios
  • Open frameworks/runtime-src/proj.ios_mac/js-multiplatform-game02.xcodeproj.

Launch as usual.

Launching the Android version

  • Make sure you have a python interpreter available.
  • Make sure Android SDK and Android NDK are installed, and that ANDROID_SDK_ROOT and NDK_ROOT are defined.
  • If using Eclipse, first time do:
    • Import js-multiplatform-game02/frameworks/js-bindings/cocos2d-x/cocos/platform/android/java into your IDE. This will create the project libcocos3dx.
    • Import js-multiplatform-game02/frameworks/runtime-src/proj.android into your IDE. This will create the js-multiplatform-game02 project.
    • Exit Eclipse, open js-multiplatform-game02/frameworks/runtime-src/proj.android/.project and remove:
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
  • Remove js-multiplatform-game02/frameworks/runtime-src/proj.android/.cproject if present

(this is because Eclipse automatically adds c-nature to projects but we will be compiling via command line)

  • Then:
    • Build the game using grunt build:android
    • Right click on js-multiplatform-game02 an "Run as" Android Application from the IDE.
  • Of if you just want to use the command line
    • Install on a device using ant -Dsdk.dir=${ANDROID_SDK_ROOT} debug install (needs ant)

Optionally, choose the desired supported Android OS versions in properties for both projects.

Advanced

Syntax and error checker (Linter, jshint)

This project uses (and enforces) a strict Javascript syntax and policy. It's using the common jshint tool to do it.

The exact policy is defined in the file .jshintrc. It may seem annoying at the beginning but it helps a lot in keeping code tidy and identifies a lot of common errors like use of undefined variables, unintended redefinition variables and so on.

Automatic syntax/error checking using Sublime text editor

If you use Sublime text editor you can have it automatically invoke jshint and highlight on screen any possible errors. I highly recommend you give it a try.

To enable it, just make sure the linter is globally available by running:

npm install -g jshint

And then in Sublime:

  • Install Package Control
  • Use it to install SublimeLinter and SublimeLinter-jshint packages
  • Restart the editor

To make life even easier, you can define the following User Settings:

  • "tab_size": 2
  • "translate_tabs_to_spaces": true
  • "rulers": [80],

Initial project creation notes

The following was used to create the base project, with cocos2d-JS.

cd ~/code
git clone https://github.com/cocos2d/cocos2d-JS/
cd cocos2d-JS
git submodule update --init
cd frameworks/js-bindings/cocos2d-x
./download-deps.py
cocos new -p com.gatillos.js02 -l js -d ~/code/ js-multiplatform-game02

After this, the structure will look something like:

- frameworks
  |- cocos2d-html5
  |- js-bindings
     |- bindings
     |- cocos2d-x
     \- external
        \- spidermonkey
  |- runtime-src
     |- Classes
        |- AppDelegate.cpp
        |- AppDelegate.h
     |- proj.android
        |- AndroidManifest.xml
        |- build.xml
        \- (...)
     |- proj.ios_mac
        - ios
          |- AppController.h
          |- AppController.mm
          |- Icons*.png
          |- Info.plist
          |- RootViewController.h
          |- RootViewController.mm
          |- main.m
          \- Prefix.pch
        - mac
          |- main.cpp
          |- Icon.icsn
          |- Info.plist
          \- Prefix.pch
        - js-multiplatform-game02.xcodeproj
          \- project.pbxproj
     |- runtime-src/proj.win32
- res
  |- CloseNormal.png
  |- CloseSelected.png
  |- HelloWorld.png
  \- favicon.ico
- runtime
  |- android
  \- ios
- src
  |- app.js
  \- resource.js
- tools
  |- bindings-generator
  \- tojs
- index.html
- main.js
- project.json
  • Had to manually copy jsbinding files from cocos2d-x: (not entirely sure way these were not copied to begin with)
cd js-multiplatform-game02/frameworks/js-bindings/cocos2d-x/plugin
cp -r ~/Downloads/cocos2d-x-3.1.1/plugin/jsbindings/manual/* jsbindings/manual/
cp -r ~/Downloads/cocos2d-x-3.1.1/plugin/jsbindings/auto/* jsbindings/auto/
cp -r ~/Downloads/cocos2d-x-3.1.1/plugin/protocols/* protocols/
  • Had to manually update iOS project paths:

Add to js-multiplatform-game02.xcodeproj, TARGET js-multiplatform-game02 iOS, on "User Header Search Paths":

$(SRCROOT)/../../js-bindings/cocos2d-x/cocos/platform/ios
  • Manually update Mac project path:

Add to js-multiplatform-game02.xcodeproj, TARGET js-multiplatform-game02 Mac, on "User Header Search Paths":

$(SRCROOT)/../../js-bindings/cocos2d-x/cocos/platform/mac
  • Manually update Resource iOS and Mac projects:

  • Add a reference (don't copy!) to jsb_ext_create_apis.js to "JS Common".

  • Add a reference to bundled_scripts.js to "JS Common".

  • Add both jsb_ext_create_api.js and bundled_scripts.js to the "Copy Bundle Resources" section, for iOS & Mac.

js-multiplatform-game02's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.