Hi,
I’m studying cocos2D-JS, and I make a small project example based in the Parkour Game Example.
The project work in plataform web, but when I run it in debug mode for Android, I get an error to click on MenuItem that start the game.
The error:
16:07:49 Starting simulator…
16:09:02 Start LaunchActivity broup.cocos.terx/org.cocos2dx.javascript.AppActivity
16:09:05 Uploading resources …
16:09:06 Uploading resources …
16:09:07 cocos2d: fullPathForFilename: No file found at script/jsb_boot.jsc. Possible missing file.
16:09:07 create rendererRecreatedListener for GLProgramState
16:09:07 debug server : client connected
16:09:07 JS: asyncListen…
16:09:07 (evaluatedOK == JS_FALSE)
16:12:15 JS: /data/data/broup.cocos.terx/files/debugruntime/src/app.js:37:ReferenceError: PlayScene is not defined
The main.js:
/**
* A brief explanation for "project.json":
* Here is the content of project.json file, this is the global configuration for your game, you can modify it to customize some behavior.
* The detail of each field is under it.
{
"project_type": "javascript",
// "project_type" indicate the program language of your project, you can ignore this field
"debugMode" : 1,
// "debugMode" possible values :
// 0 - No message will be printed.
// 1 - cc.error, cc.assert, cc.warn, cc.log will print in console.
// 2 - cc.error, cc.assert, cc.warn will print in console.
// 3 - cc.error, cc.assert will print in console.
// 4 - cc.error, cc.assert, cc.warn, cc.log will print on canvas, available only on web.
// 5 - cc.error, cc.assert, cc.warn will print on canvas, available only on web.
// 6 - cc.error, cc.assert will print on canvas, available only on web.
"showFPS" : true,
// Left bottom corner fps information will show when "showFPS" equals true, otherwise it will be hide.
"frameRate" : 60,
// "frameRate" set the wanted frame rate for your game, but the real fps depends on your game implementation and the running environment.
"id" : "gameCanvas",
// "gameCanvas" sets the id of your canvas element on the web page, it's useful only on web.
"renderMode" : 0,
// "renderMode" sets the renderer type, only useful on web :
// 0 - Automatically chosen by engine
// 1 - Forced to use canvas renderer
// 2 - Forced to use WebGL renderer, but this will be ignored on mobile browsers
"engineDir" : "frameworks/cocos2d-html5/",
// In debug mode, if you use the whole engine to develop your game, you should specify its relative path with "engineDir",
// but if you are using a single engine file, you can ignore it.
"modules" : ["cocos2d"],
// "modules" defines which modules you will need in your game, it's useful only on web,
// using this can greatly reduce your game's resource size, and the cocos console tool can package your game with only the modules you set.
// For details about modules definitions, you can refer to "../../frameworks/cocos2d-html5/modulesConfig.json".
"jsList" : [
]
// "jsList" sets the list of js files in your game.
}
*
*/
cc.game.onStart = function(){
if(!cc.sys.isNative && document.getElementById("cocosLoading")) //If referenced loading.js, please remove it
document.body.removeChild(document.getElementById("cocosLoading"));
// Pass true to enable retina display, disabled by default to improve performance
cc.view.enableRetina(false);
// Adjust viewport meta
cc.view.adjustViewPort(true);
// Setup the resolution policy and design resolution size
cc.view.setDesignResolutionSize(480, 320, cc.ResolutionPolicy.SHOW_ALL);
// The game will be resized when browser size change
cc.view.resizeWithBrowserSize(true);
//load resources
cc.LoaderScene.preload(g_resources, function () {
cc.director.runScene(new MenuScene());
}, this);
};
cc.game.run();
The app.js:
var MenuLayer = cc.Layer.extend({
ctor : function(){
//1. call super class's ctor function
this._super();
},
init:function(){
//call super class's super function
this._super();
//2. get the screen size of your game canvas
var winsize = cc.director.getWinSize();
//3. calculate the center point
var centerpos = cc.p(winsize.width / 2, winsize.height / 2);
//4. create a background image and set it's position at the center of the screen
var spritebg = new cc.Sprite(res.BackGround_png);
spritebg.setPosition(centerpos);
this.addChild(spritebg);
//5.
cc.MenuItemFont.setFontSize(60);
//6.create a menu and assign onPlay event callback to it
var menuItemPlay = new cc.MenuItemSprite(
new cc.Sprite(res.BtnPlay_png), // normal state image
new cc.Sprite(res.BtnPlay_png), // select state image
// new cc.Sprite(res.BtnPlay_png), // disabled state image
this.onPlay, this);
var menu = new cc.Menu(menuItemPlay); //7. create the menu
menu.setPosition(centerpos);
this.addChild(menu);
},
onPlay : function(){
cc.director.runScene(new PlayScene());
}
});
var MenuScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new MenuLayer();
layer.init();
this.addChild(layer);
}
});
The PlayScene.js:
var PlayScene = cc.Scene.extend({
space: null,
gameLayer:null,
shapesToRemove :[],
// init space of chipmunk
initPhysics:function() {
//1. new space object
this.space = new cp.Space();
//2. setup the Gravity
this.space.gravity = cp.v(0, -800);
// 3. set up Walls
var wallBottom = new cp.SegmentShape(this.space.staticBody,
cp.v(0, g_groundHeight),// start point
cp.v(4294967295, g_groundHeight),// MAX INT:4294967295
0);// thickness of wall
this.space.addStaticShape(wallBottom);
this.space.addCollisionHandler(SpriteTag.runner, SpriteTag.cactus,
this.collisionCactusBegin.bind(this), null, null, null);
},
collisionCactusBegin:function (arbiter, space) {
// cc.log("==game over");
cc.audioEngine.playEffect(res.Reached_mp3);
var highScore = this.getChildByTag(TagOfLayer.Status).getHighScore();
if(g_score > highScore){
this.getChildByTag(TagOfLayer.Status).updateHighScore(g_score);
}
g_contMetters = 0;
cc.director.pause();
this.addChild(new GameOverLayer());
},
onEnter:function () {
this.shapesToRemove = [];
this._super();
this.initPhysics();
this.gameLayer = new cc.Layer();
//add Background layer and Animation layer to gameLayer
this.gameLayer.addChild(new BackgroundLayer(this.space), 0, TagOfLayer.background);
this.gameLayer.addChild(new AnimationLayer(this.space), 0, TagOfLayer.Animation);
this.addChild(this.gameLayer);
this.addChild(new StatusLayer(), 0, TagOfLayer.Status);
this.scheduleUpdate();
},
update:function (dt) {
// chipmunk step
this.space.step(dt);
var animationLayer = this.gameLayer.getChildByTag(TagOfLayer.Animation);
var eyeX = animationLayer.getEyeX();
this.gameLayer.setPosition(cc.p(-eyeX,0));
}
});
The full code:
https://drive.google.com/folderview?id=0B3x7x-iJYeOAfmZuS1o1Yk9tT0JUTTJ6N1d5RWJobS1hTDBGNV9rWEZLSU5vVl9rMXQ2MVU&usp=sharing
Any ideia?
I’m sorry for my english.
Thanks!!