我正在编写一个 cocos2d 代码,想要运行我在 res 文件夹中定义的第一个场景,并且必须对其执行 ontouch 事件。我已经编写了一个代码,但它给出了一个错误“g_resources not defined”
以下是发生错误的“main.js”文件的代码:
"use strict";
var cocos2dApp = cc.Application.extend({
config : document.ccConfig,
ctor : function(scene) {
this._super();
this.startScene = scene;
cc.COCOS2D_DEBUG = this.config['COCOS2D_DEBUG'];
cc.setup(this.config['tag']);
cc.AppController.shareAppController().didFinishLaunchingWithOptions();
},
applicationDidFinishLaunching : function() {
var that = this;
// initialize director
var director = cc.Director.getInstance();
var resourceSize = cc.size(1024, 768);
var designSize = cc.size(1024, 768);
var policy = new cc.ResolutionPolicy(cc.ContainerStrategy.PROPORTION_TO_FRAME, cc.ContentStrategy.NO_BORDER);
cc.EGLView.getInstance().setDesignResolutionSize(designSize.width,designSize.height,policy);
cc.EGLView.getInstance().resizeWithBrowserSize(true);
// director.setContentScaleFactor(2,2)
// enable High Resource Mode(2x, such as iphone4) and maintains low
// resource on other devices.
// director->enableRetinaDisplay(true);
// cc.setScaleX(0.5)
// cc.setScaleY(0.5)
// this.scale(0.5,0.5)
// turn on display FPS
director.setDisplayStats(this.config['showFPS']);
// set FPS. the default value is 1.0/60 if you don't call this
director.setAnimationInterval(1.0 / this.config['frameRate']);
// create a scene. it's an autorelease object
// load resources and run
cc.LoaderScene.preload(g_resources, function() {
var startSceneInstance = new that.startScene();
director.replaceScene(startSceneInstance);
});
return true;
}
});
var myApp = new cocos2dApp(helloworldScene);
我已将所有图像存储在“resource.js”中,变量名称与 g_resources 相同。我不知道为什么它会给出这个错误。任何人都可以帮助我解决这个问题