本工具为Cocos2d-HTML5开发者提供高效和功能强大的Android Web Runtime.
- 包含加速的Cocos2d-HTML5引擎,并且支持最新的HTML5功能
- 我们还提供对Cordova的支持,开发者可以使用成千上万的Cordova插件,包括社交分享,支付以及广告等丰富的功能
了解更多的关于Cordova的信息,请访问: Cordova 和 Cordova plugins
-
配置开发环境: Windows host
请注意:您可以在其他的平台进行开发,但官方仅支持Windows和Linux平台上的开发
-
安装 Node.js
-
安装 plugman: npm install -g plugman
./bin/create Cocos2dTest com.test.Cocos2dTest Cocos2dTest
cd Cocos2dTest
将 Cocos2dTest/assets/www/*
下的文件替换为 Cocos2dTest-src/*
./cordova build
安装 out/Cocos2dTest-debug.apk
到您的Android手机并运行.
./bin/create [path package activity]
例如
./bin/create Test com.my.test Test
在 Test/assets/www
下进行游戏开发
以 cordova dialog plugin 为例:
1. 搜索 cordova dialog plugin:
#plugman search dialogs
org.apache.cordova.dialogs - Cordova Notification Plugin
com.google.google-play-services -
Google play service Plugin of Admob ,base on admob ios sdk 6.10 and android google play service sdk 4.5 ,support ios and android,support all admob banner and Interstitial
project home:https://github.com/gooogleadmob/admob-phonegap
hu.dpal.phonegap.plugins.pindialog -
PhoneGap numeric password dialog plugin for Android and iOS. Forked from https://github.com/apache/cordova-plugin-dialogs.git
ga.moviecube.mcmanager.pindialog -
PhoneGap numeric password dialog plugin for Android and iOS. Forked from https://github.com/apache/cordova-plugin-dialogs.git
#cd Test
#plugman install --platform android --plugin https://github.com/apache/cordova-plugin-dialogs.git --project .
2. 编辑 index.html
:
...
<body style="padding:0; margin: 0; background: #000;">
<canvas id="gameCanvas" width="321" height="480"></canvas>
<script type="text/javascript" src="cordova.js"></script>
+<script type="text/javascript" src="app.js"></script>
<script src="cocos2d.js"></script>
</body>
...
3. app.js:
var app = {
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onBackKey: function() {
navigator.notification.confirm(
'Exit the game?', // message
app.onConfirm, // callback to invoke
'', // title
['Ok','Cancel'] // buttonLabels
);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
document.addEventListener("backbutton", app.onBackKey, false);
},
onConfirm: function(buttonIndex) {
if (1 == buttonIndex) {
navigator.app.exitApp();
}
}
};
app.initialize();
当用户点击返回键, 将会弹出一个Dialog,而不是退出游戏.
- 通过该工具创建一个新的项目
- 在
assets/www/cocos2d.js
中: 在appFiles:[]
中加入您的游戏JS文件 assets/www/main.js
是游戏的主入口. 替换var myApp = new cocos2dApp(MyScene);
中的MyScene为您自己的游戏Scene.assets/www/engine
中包含 Cocos2d-html5 引擎, 请不要修改改目录下的文件.
请参考下面的链接: Build xwalk_core_library