-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit of the skeleton application, everything appears to w…
…ork when its not in "debug" mode.
- Loading branch information
Showing
222 changed files
with
51,499 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
cocos2d-html5-requirejs-skeleton | ||
================================ | ||
Cocos2D-HTML5 and RequireJS Integration Skeleton | ||
============= | ||
|
||
A skeleton for integrating both Cocos2d-HTML5 and RequireJS together. | ||
This is a skeleton project attempting to integrate both [Cocos2D-html5][1] and [RequireJS][2]. Hopefully it will prove to be a useful resource and save at least one person some time and effort should they decide to try and integrate the two libraries. | ||
|
||
Debug vs. Non-Debug Mode for Cocos2d-html5 | ||
------------- | ||
|
||
Cocos2d supports either a minified library or referencing the individual source files (I'm going to refer to the latter as _debug_ mode, as that seems to be the nomenclature in the cocos2d files). This skeleton is based on the Helloworld example found in the Cocos2d-html5 package, and when not run in debug mode, it seems to run correctly. | ||
|
||
However as of today (July 1st, 2012) running in debug mode causes an exception because the Cocos2d dependencies aren't loaded by the time the `App`, `AppDelegate`, and `Helloworld` modules are loaded. I've put out a call for help in understanding how I can make this work with RequireJS while in debug mode, and hopefully I can find a resolution, because nobody likes trying to track down an error in minified code! | ||
|
||
Toggling Debug Mode On-and-Off | ||
------------- | ||
|
||
In order to toggle debug mode on or off, simply go into the `app.config.js` file and set the property `isDebug` appropriately (`true` for **on**, `false` for **off**). | ||
|
||
[1]: http:https://www.cocos2d-x.org "Cocos2d-html5" | ||
[2]: http:https://www.requirejs.org "RequireJS" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* | ||
*/ | ||
|
||
var appConfig = { | ||
/* (non-JSDoc) | ||
* The base URL, prepended to all files loaded via the loadjs() function. | ||
*/ | ||
baseUrl: './', | ||
|
||
/* (non-JSDoc) | ||
* Whether or not this script should attempt loading the production or | ||
* development code. | ||
*/ | ||
isDebug: false, | ||
|
||
/* (non-JSDoc) | ||
* Whether or not to use require JS. | ||
*/ | ||
useRequireJs: true, | ||
|
||
/* (non-JSDoc) | ||
* The modules supported when loading | ||
*/ | ||
modules: { | ||
'cocos2d-0.5.0-alpha2': { | ||
version: '0.5.0-alpha2', | ||
path: 'lib/dev/cocos2d-html5-v0.5.0-alpha2/' | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/**************************************************************************** | ||
Copyright (c) 2010-2012 cocos2d-x.org | ||
Copyright (c) 2008-2010 Ricardo Quesada | ||
Copyright (c) 2011 Zynga Inc. | ||
http:https://www.cocos2d-x.org | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
****************************************************************************/ | ||
|
||
/* (non-JSdoc) | ||
* Modified original HelloWorld sample from Cocos2D-HTML5 package to use | ||
* RequireJS. | ||
*/ | ||
define(function (require, exports, modules) { | ||
var cocos2d = require('cocos2d'); | ||
var AppDelegate = require('Assets/AppDelegate'); | ||
|
||
var Application = function() { | ||
cc.COCOS2D_DEBUG = 2; | ||
cc._DEBUG = 1; | ||
cc._IS_RETINA_DISPLAY_SUPPORTED = 0; | ||
}; | ||
|
||
Application.prototype = { | ||
|
||
initialize: function() { | ||
cc.setup("gameCanvas"); | ||
cc.AudioManager.sharedEngine().init("mp3"); | ||
cc.AppDelegate = AppDelegate; | ||
|
||
// ** We are ready to run the game | ||
cc.Loader.shareLoader().onloading = function () { | ||
cc.LoaderScene.shareLoaderScene().draw(); | ||
}; | ||
|
||
cc.Loader.shareLoader().onload = function () { | ||
cc.AppController.shareAppController().didFinishLaunchingWithOptions(); | ||
}; | ||
|
||
// ** Preload resources | ||
cc.Loader.shareLoader().preload([ | ||
{type:"image", src:"assets/images/HelloWorld.png"}, | ||
{type:"image", src:"assets/images/CloseNormal.png"}, | ||
{type:"image", src:"assets/images/CloseSelected.png"} | ||
]); | ||
} | ||
} | ||
return Application; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/**************************************************************************** | ||
Copyright (c) 2010-2012 cocos2d-x.org | ||
Copyright (c) 2008-2010 Ricardo Quesada | ||
Copyright (c) 2011 Zynga Inc. | ||
http:https://www.cocos2d-x.org | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
****************************************************************************/ | ||
|
||
/* (non-JSdoc) | ||
* Modified original HelloWorld sample from Cocos2D-HTML5 package to use | ||
* RequireJS. | ||
*/ | ||
define(function(require, exports, module) { | ||
var cocos2d = require('cocos2d'); | ||
var Helloworld = require('Assets/Helloworld'); | ||
|
||
/** | ||
* @brief The cocos2d Application. | ||
* The reason for implement as private inheritance is to hide some interface call by CCDirector. | ||
*/ | ||
var appDelegate = cc.Application.extend({ | ||
ctor:function () { | ||
this._super(); | ||
}, | ||
|
||
/** | ||
* @brief Implement for initialize OpenGL instance, set source path, etc... | ||
*/ | ||
initInstance:function () { | ||
return true; | ||
}, | ||
|
||
/** | ||
* @brief Implement CCDirector and CCScene init code here. | ||
* @return true Initialize success, app continue. | ||
* @return false Initialize failed, app terminate. | ||
*/ | ||
applicationDidFinishLaunching:function () { | ||
// initialize director | ||
var director = cc.Director.sharedDirector(); | ||
director.setDisplayFPS(true); | ||
director.setAnimationInterval(1.0 / 60); | ||
var scene = Helloworld.scene(); | ||
director.runWithScene(scene); | ||
return true; | ||
}, | ||
|
||
/** | ||
* @brief The function be called when the application enter background | ||
* @param the pointer of the application | ||
*/ | ||
applicationDidEnterBackground:function () { | ||
cc.Director.sharedDirector().pause(); | ||
}, | ||
|
||
/** | ||
* @brief The function be called when the application enter foreground | ||
* @param the pointer of the application | ||
*/ | ||
applicationWillEnterForeground:function () { | ||
cc.Director.sharedDirector().resume(); | ||
} | ||
}); | ||
return appDelegate; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/**************************************************************************** | ||
Copyright (c) 2010-2012 cocos2d-x.org | ||
Copyright (c) 2008-2010 Ricardo Quesada | ||
Copyright (c) 2011 Zynga Inc. | ||
http:https://www.cocos2d-x.org | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
****************************************************************************/ | ||
|
||
/* (non-JSdoc) | ||
* Modified original HelloWorld sample from Cocos2D-HTML5 package to use | ||
* RequireJS. | ||
*/ | ||
define(function(require) { | ||
var cocos2d = require('cocos2d'); | ||
|
||
var Helloworld = cc.Layer.extend({ | ||
isMouseDown:false, | ||
helloImg:null, | ||
helloLabel:null, | ||
circle:null, | ||
sprite:null, | ||
|
||
init:function () { | ||
|
||
////////////////////////////// | ||
// 1. super init first | ||
this._super(); | ||
|
||
///////////////////////////// | ||
// 2. add a menu item with "X" image, which is clicked to quit the program | ||
// you may modify it. | ||
// ask director the window size | ||
var size = cc.Director.sharedDirector().getWinSize(); | ||
|
||
// add a "close" icon to exit the progress. it's an autorelease object | ||
var closeItem = cc.MenuItemImage.create( | ||
"assets/images/CloseNormal.png", | ||
"assets/images/CloseSelected.png", | ||
this, | ||
function () { | ||
history.go(-1); | ||
}); | ||
closeItem.setAnchorPoint(new cc.Point(0.5,0.5)); | ||
|
||
var menu = cc.Menu.create(closeItem, null); | ||
menu.setPosition( cc.PointZero() ); | ||
this.addChild(menu, 1); | ||
closeItem.setPosition(new cc.Point(size.width -20 , 20)); | ||
|
||
///////////////////////////// | ||
// 3. add your codes below... | ||
// add a label shows "Hello World" | ||
// create and initialize a label | ||
this.helloLabel = cc.LabelTTF.create("Hello World", "Arial", 38); | ||
// position the label on the center of the screen | ||
this.helloLabel.setPosition(cc.ccp(size.width / 2, size.height - 40)); | ||
// add the label as a child to this layer | ||
this.addChild(this.helloLabel, 5); | ||
|
||
var lazyLayer = new cc.LazyLayer(); | ||
this.addChild(lazyLayer); | ||
|
||
// add "HelloWorld" splash screen" | ||
this.sprite = cc.Sprite.create("assets/images/HelloWorld.png"); | ||
this.sprite.setAnchorPoint(cc.ccp(0.5, 0.5)); | ||
this.sprite.setPosition(cc.ccp(size.width / 2, size.height / 2)); | ||
|
||
lazyLayer.addChild(this.sprite, 0); | ||
|
||
return true; | ||
} | ||
}); | ||
|
||
Helloworld.scene = function () { | ||
// 'scene' is an autorelease object | ||
var scene = cc.Scene.create(); | ||
|
||
// 'layer' is an autorelease object | ||
var layer = this.node(); | ||
scene.addChild(layer); | ||
return scene; | ||
}; | ||
// implement the "static node()" method manually | ||
Helloworld.node = function () { | ||
var ret = new Helloworld(); | ||
|
||
// Init the helloworld display layer. | ||
if (ret && ret.init()) { | ||
return ret; | ||
} | ||
|
||
return null; | ||
}; | ||
return Helloworld; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0"?> | ||
<project name="Javascript compress project" basedir="." default="compile"> | ||
|
||
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask" | ||
classpath="${basedir}/../tools/compiler/compiler.jar"/> | ||
|
||
<target name="compile"> | ||
<jscomp compilationLevel="simple" warning="quiet" | ||
debug="false" output="cocos2d-html5-alpha-min.js"> | ||
<sources dir="${basedir}/../cocos2d"> | ||
<file name="platform/CCClass.js"/> | ||
<file name="platform/CCCommon.js"/> | ||
<file name="platform/platform.js"/> | ||
<file name="cocoa/CCGeometry.js"/> | ||
<file name="cocoa/CCSet.js"/> | ||
<file name="cocoa/CCNS.js"/> | ||
<file name="platform/CCTypes.js"/> | ||
<file name="cocoa/CCAffineTransform.js"/> | ||
<file name="support/CCPointExtension.js"/> | ||
<file name="base_nodes/CCNode.js"/> | ||
<file name="platform/CCMacro.js"/> | ||
<file name="platform/CCConfig.js"/> | ||
<file name="textures/CCTexture2D.js"/> | ||
<file name="textures/CCTextureCache.js"/> | ||
<file name="actions/CCAction.js"/> | ||
<file name="actions/CCActionInterval.js"/> | ||
<file name="actions/CCActionManager.js"/> | ||
<file name="actions/CCActionEase.js"/> | ||
<file name="layers_scenes_transitions_nodes/CCScene.js"/> | ||
<file name="layers_scenes_transitions_nodes/CCLayer.js"/> | ||
<file name="layers_scenes_transitions_nodes/CCTransition.js"/> | ||
<file name="sprite_nodes/CCSprite.js"/> | ||
<file name="label_nodes/CCLabelTTF.js"/> | ||
<file name="text_input_node/CCIMEDispatcher.js"/> | ||
<file name="touch_dispatcher/CCTouchDelegateProtocol.js"/> | ||
<file name="touch_dispatcher/CCTouchHandler.js"/> | ||
<file name="touch_dispatcher/CCTouchDispatcher.js"/> | ||
<file name="keypad_dispatcher/CCKeypadDelegate.js"/> | ||
<file name="keypad_dispatcher/CCKeypadDispatcher.js"/> | ||
<file name="CCDirector.js"/> | ||
<file name="CCScheduler.js"/> | ||
<file name="CCLoader.js"/> | ||
<file name="CCDrawingPrimitives.js"/> | ||
<file name="platform/CCApplication.js"/> | ||
<file name="platform/CCSAXParser.js"/> | ||
<file name="platform/AppControl.js"/> | ||
<file name="menu_nodes/CCMenuItem.js"/> | ||
<file name="menu_nodes/CCMenu.js"/> | ||
</sources> | ||
<sources dir="${basedir}/../CocosDenshion"> | ||
<file name="SimpleAudioEngine.js"/> | ||
</sources> | ||
</jscomp> | ||
</target> | ||
</project> |
Oops, something went wrong.