mirror of https://github.com/axmolengine/axmol.git
Updating template for cocos2d-x JS
This commit is contained in:
parent
7305442803
commit
7381abffb3
|
@ -1,3 +1,4 @@
|
|||
require("jsb_constants.js");
|
||||
|
||||
try {
|
||||
|
||||
|
@ -161,8 +162,10 @@ try {
|
|||
var game = GameCreator();
|
||||
|
||||
__jsc__.garbageCollect();
|
||||
|
||||
// LOADING PLAY SCENE UNTILL CCBREADER IS FIXED
|
||||
|
||||
director.runWithScene(game.getMainMenuScene());
|
||||
director.runWithScene(game.getPlayScene());
|
||||
|
||||
} catch(e) {log(e);}
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
//
|
||||
// Javascript Bindigns helper file
|
||||
//
|
||||
|
||||
// DO NOT ALTER THE ORDER
|
||||
require('jsb_constants_cocos2d.js');
|
||||
//require('jsb_constants_chipmunk.js');
|
||||
require('jsb_constants_gl.js');
|
||||
require('jsb_constants_cocosbuilder.js');
|
|
@ -0,0 +1,253 @@
|
|||
//
|
||||
// Chipmunk defines
|
||||
//
|
||||
|
||||
cp.v = cc.p;
|
||||
cp._v = cc._p;
|
||||
cp.vzero = cp.v(0,0);
|
||||
|
||||
// Vector: Compatibility with Chipmunk-JS
|
||||
cp.v.add = cp.vadd;
|
||||
cp.v.clamp = cp.vclamp;
|
||||
cp.v.cross = cp.vcross;
|
||||
cp.v.dist = cp.vdist;
|
||||
cp.v.distsq = cp.vdistsq;
|
||||
cp.v.dot = cp.vdot;
|
||||
cp.v.eql = cp.veql;
|
||||
cp.v.forangle = cp.vforangle;
|
||||
cp.v.len = cp.vlength;
|
||||
cp.v.lengthsq = cp.vlengthsq;
|
||||
cp.v.lerp = cp.vlerp;
|
||||
cp.v.lerpconst = cp.vlerpconst;
|
||||
cp.v.mult = cp.vmult;
|
||||
cp.v.near = cp.vnear;
|
||||
cp.v.neg = cp.vneg;
|
||||
cp.v.normalize = cp.vnormalize;
|
||||
cp.v.normalize_safe = cp.vnormalize_safe;
|
||||
cp.v.perp = cp.vperp;
|
||||
cp.v.project = cp.vproject;
|
||||
cp.v.rotate = cp.vrotate;
|
||||
cp.v.rperp = cp.vrperp;
|
||||
cp.v.slerp = cp.vslerp;
|
||||
cp.v.slerpconst = cp.vslerpconst;
|
||||
cp.v.sub = cp.vsub;
|
||||
cp.v.toangle = cp.vtoangle;
|
||||
cp.v.unrotate = cp.vunrotate;
|
||||
|
||||
|
||||
|
||||
/// Initialize an offset box shaped polygon shape.
|
||||
cp.BoxShape2 = function(body, box)
|
||||
{
|
||||
var verts = [
|
||||
box.l, box.b,
|
||||
box.l, box.t,
|
||||
box.r, box.t,
|
||||
box.r, box.b
|
||||
];
|
||||
|
||||
return new cp.PolyShape(body, verts, cp.vzero);
|
||||
};
|
||||
|
||||
/// Initialize a box shaped polygon shape.
|
||||
cp.BoxShape = function(body, width, height)
|
||||
{
|
||||
var hw = width/2;
|
||||
var hh = height/2;
|
||||
|
||||
return cp.BoxShape2(body, new cp.BB(-hw, -hh, hw, hh));
|
||||
};
|
||||
|
||||
|
||||
/// Initialize an static body
|
||||
cp.BodyStatic = function()
|
||||
{
|
||||
return new cp.Body(Infinity, Infinity);
|
||||
};
|
||||
|
||||
|
||||
// "Bounding Box" compatibility with Chipmunk-JS
|
||||
cp.BB = function(l, b, r, t)
|
||||
{
|
||||
return {l:l, b:b, r:r, t:t};
|
||||
};
|
||||
|
||||
// helper function to create a BB
|
||||
cp.bb = function(l, b, r, t) {
|
||||
return new cp.BB(l, b, r, t);
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Some properties
|
||||
//
|
||||
// "handle" needed in some cases
|
||||
Object.defineProperties(cp.Base.prototype,
|
||||
{
|
||||
"handle" : {
|
||||
get : function(){
|
||||
return this.getHandle();
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
});
|
||||
|
||||
// Properties, for Chipmunk-JS compatibility
|
||||
// Space properties
|
||||
Object.defineProperties(cp.Space.prototype,
|
||||
{
|
||||
"gravity" : {
|
||||
get : function(){
|
||||
return this.getGravity();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setGravity(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"iterations" : {
|
||||
get : function(){
|
||||
return this.getIterations();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setIterations(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"damping" : {
|
||||
get : function(){
|
||||
return this.getDamping();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setDamping(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"staticBody" : {
|
||||
get : function(){
|
||||
return this.getStaticBody();
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"idleSpeedThreshold" : {
|
||||
get : function(){
|
||||
return this.getIdleSpeedThreshold();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setIdleSpeedThreshold(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"sleepTimeThreshold": {
|
||||
get : function(){
|
||||
return this.getSleepTimeThreshold();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setSleepTimeThreshold(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"collisionSlop": {
|
||||
get : function(){
|
||||
return this.getCollisionSlop();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setCollisionSlop(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"collisionBias": {
|
||||
get : function(){
|
||||
return this.getCollisionBias();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setCollisionBias(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"collisionPersistence": {
|
||||
get : function(){
|
||||
return this.getCollisionPersistence();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setCollisionPersistence(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"enableContactGraph": {
|
||||
get : function(){
|
||||
return this.getEnableContactGraph();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setEnableContactGraph(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
});
|
||||
|
||||
// Body properties
|
||||
Object.defineProperties(cp.Body.prototype,
|
||||
{
|
||||
"a" : {
|
||||
get : function(){
|
||||
return this.getAngle();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setAngle(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"w" : {
|
||||
get : function(){
|
||||
return this.getAngVel();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setAngVel(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"p" : {
|
||||
get : function(){
|
||||
return this.getPos();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setPos(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"v" : {
|
||||
get : function(){
|
||||
return this.getVel();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setVel(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
},
|
||||
"i" : {
|
||||
get : function(){
|
||||
return this.getMoment();
|
||||
},
|
||||
set : function(newValue){
|
||||
this.setMoment(newValue);
|
||||
},
|
||||
enumerable : true,
|
||||
configurable : true
|
||||
}
|
||||
|
||||
});
|
|
@ -0,0 +1,484 @@
|
|||
//
|
||||
// cocos2d constants
|
||||
//
|
||||
cc.DIRECTOR_PROJECTION_2D = 0;
|
||||
cc.DIRECTOR_PROJECTION_3D = 1;
|
||||
|
||||
cc.TEXTURE_PIXELFORMAT_RGBA8888 = 0;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB888 = 1;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB565 = 2;
|
||||
cc.TEXTURE_PIXELFORMAT_A8 = 3;
|
||||
cc.TEXTURE_PIXELFORMAT_I8 = 4;
|
||||
cc.TEXTURE_PIXELFORMAT_AI88 = 5;
|
||||
cc.TEXTURE_PIXELFORMAT_RGBA4444 = 6;
|
||||
cc.TEXTURE_PIXELFORMAT_RGB5A1 = 7;
|
||||
cc.TEXTURE_PIXELFORMAT_PVRTC4 = 8;
|
||||
cc.TEXTURE_PIXELFORMAT_PVRTC4 = 9;
|
||||
cc.TEXTURE_PIXELFORMAT_DEFAULT = cc.TEXTURE_PIXELFORMAT_RGBA8888;
|
||||
|
||||
cc.TEXT_ALIGNMENT_LEFT = 0;
|
||||
cc.TEXT_ALIGNMENT_CENTER = 1;
|
||||
cc.TEXT_ALIGNMENT_RIGHT = 2;
|
||||
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_TOP = 0;
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_CENTER = 1;
|
||||
cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM = 2;
|
||||
|
||||
cc.IMAGE_FORMAT_JPEG = 0;
|
||||
cc.IMAGE_FORMAT_PNG = 0;
|
||||
|
||||
cc.PROGRESS_TIMER_TYPE_RADIAL = 0;
|
||||
cc.PROGRESS_TIMER_TYPE_BAR = 1;
|
||||
|
||||
cc.PARTICLE_TYPE_FREE = 0;
|
||||
cc.PARTICLE_TYPE_RELATIVE = 1;
|
||||
cc.PARTICLE_TYPE_GROUPED = 2;
|
||||
cc.PARTICLE_DURATION_INFINITY = -1;
|
||||
cc.PARTICLE_MODE_GRAVITY = 0;
|
||||
cc.PARTICLE_MODE_RADIUS = 1;
|
||||
cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE = -1;
|
||||
cc.PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS = -1;
|
||||
|
||||
cc.TOUCH_ALL_AT_ONCE = 0;
|
||||
cc.TOUCH_ONE_BY_ONE = 1;
|
||||
|
||||
cc.TMX_TILE_HORIZONTAL_FLAG = 0x80000000;
|
||||
cc.TMX_TILE_VERTICAL_FLAG = 0x40000000;
|
||||
cc.TMX_TILE_DIAGONAL_FLAG = 0x20000000;
|
||||
|
||||
cc.TRANSITION_ORIENTATION_LEFT_OVER = 0;
|
||||
cc.TRANSITION_ORIENTATION_RIGHT_OVER = 1;
|
||||
cc.TRANSITION_ORIENTATION_UP_OVER = 0;
|
||||
cc.TRANSITION_ORIENTATION_DOWN_OVER = 1;
|
||||
|
||||
cc.RED = {r:255, g:0, b:0};
|
||||
cc.GREEN = {r:0, g:255, b:0};
|
||||
cc.BLUE = {r:0, g:0, b:255};
|
||||
cc.BLACK = {r:0, g:0, b:0};
|
||||
cc.WHITE = {r:255, g:255, b:255};
|
||||
|
||||
cc.POINT_ZERO = {x:0, y:0};
|
||||
|
||||
// XXX: This definition is different than cocos2d-html5
|
||||
cc.REPEAT_FOREVER = -1;
|
||||
// reusable objects
|
||||
cc._reuse_p = [
|
||||
{x:0, y:0},
|
||||
{x:0, y:0},
|
||||
{x:0, y:0},
|
||||
{x:0, y:0}
|
||||
];
|
||||
|
||||
cc._reuse_p_index = 0;
|
||||
cc._reuse_size = {width:0, height:0};
|
||||
cc._reuse_rect = {x:0, y:0, width:0, height:0};
|
||||
cc._reuse_color3b = {r:255, g:255, b:255 };
|
||||
cc._reuse_color4b = {r:255, g:255, b:255, a:255 };
|
||||
|
||||
//
|
||||
// Point
|
||||
//
|
||||
cc.p = function( x, y )
|
||||
{
|
||||
return {x:x, y:y};
|
||||
};
|
||||
|
||||
cc.g = cc.g || cc.p;
|
||||
cc._reuse_grid = cc.g(0,0);
|
||||
|
||||
cc.log = cc.log || log;
|
||||
|
||||
//
|
||||
// Color 3B
|
||||
//
|
||||
cc.c3b = function (r, g, b) {
|
||||
return {r:r, g:g, b:b };
|
||||
};
|
||||
cc._c3b = function (r, g, b) {
|
||||
cc._reuse_color3b.r = r;
|
||||
cc._reuse_color3b.g = g;
|
||||
cc._reuse_color3b.b = b;
|
||||
return cc._reuse_color3b;
|
||||
};
|
||||
|
||||
//
|
||||
// Color 4B
|
||||
//
|
||||
cc.c4b = function (r, g, b, a) {
|
||||
return {r:r, g:g, b:b, a:a };
|
||||
};
|
||||
cc._c4b = function (r, g, b, a) {
|
||||
cc._reuse_color4b.r = r;
|
||||
cc._reuse_color4b.g = g;
|
||||
cc._reuse_color4b.b = b;
|
||||
cc._reuse_color4b.a = a;
|
||||
return cc._reuse_color4b;
|
||||
};
|
||||
// compatibility
|
||||
cc.c4 = cc.c4b;
|
||||
cc._c4 = cc._c4b;
|
||||
|
||||
//
|
||||
// Color 4F
|
||||
//
|
||||
cc.c4f = function (r, g, b, a) {
|
||||
return {r:r, g:g, b:b, a:a };
|
||||
};
|
||||
|
||||
//
|
||||
// Point
|
||||
//
|
||||
cc.p = function (x, y) {
|
||||
return {x:x, y:y};
|
||||
};
|
||||
cc._p = function (x, y) {
|
||||
if (cc._reuse_p_index == cc._reuse_p.length)
|
||||
cc._reuse_p_index = 0;
|
||||
|
||||
var p = cc._reuse_p[ cc._reuse_p_index];
|
||||
cc._reuse_p_index++;
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
return p;
|
||||
};
|
||||
|
||||
cc.pointEqualToPoint = function (point1, point2) {
|
||||
return ((point1.x == point2.x) && (point1.y == point2.y));
|
||||
};
|
||||
|
||||
//
|
||||
// Grid
|
||||
//
|
||||
cc.g = function (x, y) {
|
||||
return {x:x, y:y};
|
||||
};
|
||||
cc._g = function (x, y) {
|
||||
cc._reuse_grid.x = x;
|
||||
cc._reuse_grid.y = y;
|
||||
return cc._reuse_grid;
|
||||
};
|
||||
|
||||
//
|
||||
// Size
|
||||
//
|
||||
cc.size = function (w, h) {
|
||||
return {width:w, height:h};
|
||||
};
|
||||
cc._size = function (w, h) {
|
||||
cc._reuse_size.width = w;
|
||||
cc._reuse_size.height = h;
|
||||
return cc._reuse_size;
|
||||
};
|
||||
cc.sizeEqualToSize = function (size1, size2) {
|
||||
return ((size1.width == size2.width) && (size1.height == size2.height));
|
||||
};
|
||||
|
||||
//
|
||||
// Rect
|
||||
//
|
||||
cc.rect = function (x, y, w, h) {
|
||||
return {x:x, y:y, width:w, height:h};
|
||||
};
|
||||
cc._rect = function(x,y,w,h)
|
||||
{
|
||||
cc._reuse_rect.x = x;
|
||||
cc._reuse_rect.y = y;
|
||||
cc._reuse_rect.width = w;
|
||||
cc._reuse_rect.height = h;
|
||||
return cc._reuse_rect;
|
||||
};
|
||||
cc.rectEqualToRect = function (rect1, rect2) {
|
||||
return ( rect1.x==rect2.x && rect1.y==rect2.y && rect1.width==rect2.width && rect1.height==rect2.height);
|
||||
};
|
||||
|
||||
cc._rect = function (x, y, w, h) {
|
||||
cc._reuse_rect.x = x;
|
||||
cc._reuse_rect.y = y;
|
||||
cc._reuse_rect.width = w;
|
||||
cc._reuse_rect.height = h;
|
||||
return cc._reuse_rect;
|
||||
};
|
||||
cc.rectEqualToRect = function (rect1, rect2) {
|
||||
return ( rect1.x == rect2.x && rect1.y == rect2.y && rect1.width == rect2.width && rect1.height == rect2.height);
|
||||
};
|
||||
|
||||
cc.rectContainsRect = function (rect1, rect2) {
|
||||
if ((rect1.x >= rect2.x) || (rect1.y >= rect2.y) ||
|
||||
( rect1.x + rect1.width <= rect2.x + rect2.width) ||
|
||||
( rect1.y + rect1.height <= rect2.y + rect2.height))
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
cc.rectGetMaxX = function (rect) {
|
||||
return (rect.x + rect.width);
|
||||
};
|
||||
|
||||
cc.rectGetMidX = function (rect) {
|
||||
return (rect.x + rect.width / 2.0);
|
||||
};
|
||||
|
||||
cc.rectGetMinX = function (rect) {
|
||||
return rect.x;
|
||||
};
|
||||
|
||||
cc.rectGetMaxY = function (rect) {
|
||||
return(rect.y + rect.height);
|
||||
};
|
||||
|
||||
cc.rectGetMidY = function (rect) {
|
||||
return rect.y + rect.height / 2.0;
|
||||
};
|
||||
|
||||
cc.rectGetMinY = function (rect) {
|
||||
return rect.y;
|
||||
};
|
||||
|
||||
cc.rectContainsPoint = function (rect, point) {
|
||||
var ret = false;
|
||||
if (point.x >= rect.x && point.x <= rect.x + rect.width &&
|
||||
point.y >= rect.y && point.y <= rect.y + rect.height) {
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
// XXX Should be done in native
|
||||
cc.rectIntersectsRect = function (rectA, rectB) {
|
||||
var bool = !( rectA.x > rectB.x + rectB.width ||
|
||||
rectA.x + rectA.width < rectB.x ||
|
||||
rectA.y > rectB.y + rectB.height ||
|
||||
rectA.y + rectA.height < rectB.y );
|
||||
|
||||
return bool;
|
||||
};
|
||||
|
||||
cc.rectUnion = function (rectA, rectB) {
|
||||
var rect = cc.rect(0, 0, 0, 0);
|
||||
rect.x = Math.min(rectA.x, rectB.x);
|
||||
rect.y = Math.min(rectA.y, rectB.y);
|
||||
rect.width = Math.max(rectA.x + rectA.width, rectB.x + rectB.width) - rect.x;
|
||||
rect.height = Math.max(rectA.y + rectA.height, rectB.y + rectB.height) - rect.y;
|
||||
return rect;
|
||||
};
|
||||
|
||||
cc.rectIntersection = function (rectA, rectB) {
|
||||
var intersection = cc.rect(
|
||||
Math.max(rectA.x, rectB.x),
|
||||
Math.max(rectA.y, rectB.y),
|
||||
0, 0);
|
||||
|
||||
intersection.width = Math.min(rectA.x + rectA.width, rectB.x + rectB.width) - intersection.x;
|
||||
intersection.height = Math.min(rectA.y + rectA.height, rectB.y + rectB.height) - intersection.y;
|
||||
return intersection;
|
||||
};
|
||||
|
||||
//
|
||||
// Array: for cocos2d-html5 compatibility
|
||||
//
|
||||
cc.ArrayRemoveObject = function (arr, delObj) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (arr[i] == delObj) {
|
||||
arr.splice(i, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Helpers
|
||||
//
|
||||
cc.dump = function (obj) {
|
||||
for (var i in obj)
|
||||
cc.log(i + " = " + obj[i]);
|
||||
};
|
||||
|
||||
// dump config info, but only in debug mode
|
||||
cc.dumpConfig = function () {
|
||||
if (cc.config.debug)
|
||||
cc.dump(cc.config);
|
||||
};
|
||||
|
||||
//
|
||||
// Bindings Overrides
|
||||
//
|
||||
// MenuItemToggle
|
||||
cc.MenuItemToggle.create = function( /* var args */) {
|
||||
|
||||
cc.rectGetMinX = function (rect) {
|
||||
return rect.x;
|
||||
};
|
||||
|
||||
if (typeof arguments[n-2] === 'function' || typeof arguments[n-1] === 'function') {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var obj = null;
|
||||
if( typeof arguments[n-2] === 'function' )
|
||||
obj = args.pop();
|
||||
|
||||
var func = args.pop();
|
||||
|
||||
// create it with arguments,
|
||||
var item = cc.MenuItemToggle._create.apply(this, args);
|
||||
|
||||
// then set the callback
|
||||
if( obj !== null )
|
||||
item.setCallback(func, obj);
|
||||
else
|
||||
item.setCallback(func);
|
||||
return item;
|
||||
} else {
|
||||
return cc.MenuItemToggle._create.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
// LabelAtlas
|
||||
cc.LabelAtlas.create = function( a,b,c,d,e ) {
|
||||
|
||||
var n = arguments.length;
|
||||
|
||||
if ( n == 5) {
|
||||
return cc.LabelAtlas._create(a,b,c,d,e.charCodeAt(0));
|
||||
} else {
|
||||
return cc.LabelAtlas._create.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Associates a base class with a native superclass
|
||||
* @function
|
||||
* @param {object} jsobj subclass
|
||||
* @param {object} klass superclass
|
||||
*/
|
||||
cc.associateWithNative = function (jsobj, superclass_or_instance) {
|
||||
|
||||
try {
|
||||
// Used when subclassing using the "extend" method
|
||||
var native = new superclass_or_instance();
|
||||
__associateObjWithNative(jsobj, native);
|
||||
} catch (err) {
|
||||
// Used when subclassing using the goog.inherits method
|
||||
__associateObjWithNative(jsobj, superclass_or_instance);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// JSB supports 2 official ways to create subclasses
|
||||
//
|
||||
// 1) Google "subclasses" borrowed from closure library
|
||||
// This is the recommended way to do it
|
||||
//
|
||||
|
||||
cc.inherits = function (childCtor, parentCtor) {
|
||||
/** @constructor */
|
||||
function tempCtor() {};
|
||||
tempCtor.prototype = parentCtor.prototype;
|
||||
childCtor.superClass_ = parentCtor.prototype;
|
||||
childCtor.prototype = new tempCtor();
|
||||
childCtor.prototype.constructor = childCtor;
|
||||
|
||||
// Copy "static" method, but doesn't generate subclasses.
|
||||
// for( var i in parentCtor ) {
|
||||
// childCtor[ i ] = parentCtor[ i ];
|
||||
// }
|
||||
};
|
||||
|
||||
cc.base = function (me, opt_methodName, var_args) {
|
||||
var caller = arguments.callee.caller;
|
||||
if (caller.superClass_) {
|
||||
// This is a constructor. Call the superclass constructor.
|
||||
ret = caller.superClass_.constructor.apply(me, Array.prototype.slice.call(arguments, 1));
|
||||
return ret;
|
||||
}
|
||||
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
var foundCaller = false;
|
||||
for (var ctor = me.constructor;
|
||||
ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
|
||||
if (ctor.prototype[opt_methodName] === caller) {
|
||||
foundCaller = true;
|
||||
} else if (foundCaller) {
|
||||
return ctor.prototype[opt_methodName].apply(me, args);
|
||||
}
|
||||
}
|
||||
|
||||
// If we did not find the caller in the prototype chain,
|
||||
// then one of two things happened:
|
||||
// 1) The caller is an instance method.
|
||||
// 2) This method was not called by the right caller.
|
||||
if (me[opt_methodName] === caller) {
|
||||
return me.constructor.prototype[opt_methodName].apply(me, args);
|
||||
} else {
|
||||
throw Error(
|
||||
'cc.base called from a method of one name ' +
|
||||
'to a method of a different name');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// 2) Using "extend" subclassing
|
||||
// Simple JavaScript Inheritance By John Resig http://ejohn.org/
|
||||
//
|
||||
cc.Class = function () {};
|
||||
cc.Class.extend = function (prop) {
|
||||
var _super = this.prototype;
|
||||
|
||||
// Instantiate a base class (but only create the instance,
|
||||
// don't run the init constructor)
|
||||
initializing = true;
|
||||
var prototype = new this();
|
||||
initializing = false;
|
||||
fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
||||
|
||||
// Copy the properties over onto the new prototype
|
||||
for (var name in prop) {
|
||||
// Check if we're overwriting an existing function
|
||||
prototype[name] = typeof prop[name] == "function" &&
|
||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||
(function (name, fn) {
|
||||
return function () {
|
||||
var tmp = this._super;
|
||||
|
||||
// Add a new ._super() method that is the same method
|
||||
// but on the super-class
|
||||
this._super = _super[name];
|
||||
|
||||
// The method only need to be bound temporarily, so we
|
||||
// remove it when we're done executing
|
||||
var ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
|
||||
return ret;
|
||||
};
|
||||
})(name, prop[name]) :
|
||||
prop[name];
|
||||
}
|
||||
|
||||
// The dummy class constructor
|
||||
function Class() {
|
||||
// All construction is actually done in the init method
|
||||
if (!initializing && this.ctor)
|
||||
this.ctor.apply(this, arguments);
|
||||
}
|
||||
|
||||
// Populate our constructed prototype object
|
||||
Class.prototype = prototype;
|
||||
|
||||
// Enforce the constructor to be what we expect
|
||||
Class.prototype.constructor = Class;
|
||||
|
||||
// And make this class extendable
|
||||
Class.extend = arguments.callee;
|
||||
|
||||
return Class;
|
||||
};
|
||||
|
||||
cc.Node.prototype.ctor = function () {};
|
||||
cc.Node.extend = cc.Class.extend;
|
||||
cc.Layer.extend = cc.Class.extend;
|
||||
cc.LayerGradient.extend = cc.Class.extend;
|
||||
cc.LayerColor.extend = cc.Class.extend;
|
||||
cc.Sprite.extend = cc.Class.extend;
|
||||
cc.MenuItemFont.extend = cc.Class.extend;
|
||||
cc.Scene.extend = cc.Class.extend;
|
118
template/xcode4/cocos2dx_js.xctemplate/Resources/jsb_constants_cocosbuilder.js
vendored
Normal file
118
template/xcode4/cocos2dx_js.xctemplate/Resources/jsb_constants_cocosbuilder.js
vendored
Normal file
|
@ -0,0 +1,118 @@
|
|||
//
|
||||
// CocosBuilder definitions
|
||||
//
|
||||
|
||||
cc.Reader = {};
|
||||
|
||||
var _ccbGlobalContext = this;
|
||||
|
||||
cc.Reader.load = function(file, owner, parentSize)
|
||||
{
|
||||
// Load the node graph using the correct function
|
||||
var reader = cc._Reader.create();
|
||||
var node;
|
||||
|
||||
if (owner && parentSize)
|
||||
{
|
||||
node = reader.load(file, owner, parentSize);
|
||||
}
|
||||
else if (owner)
|
||||
{
|
||||
node = reader.load(file,owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = reader.load(file);
|
||||
}
|
||||
|
||||
// Assign owner callbacks & member variables
|
||||
if (owner)
|
||||
{
|
||||
// Callbacks
|
||||
var ownerCallbackNames = reader.getOwnerCallbackNames();
|
||||
var ownerCallbackNodes = reader.getOwnerCallbackNodes();
|
||||
|
||||
for (var i = 0; i < ownerCallbackNames.length; i++)
|
||||
{
|
||||
var callbackName = ownerCallbackNames[i];
|
||||
var callbackNode = ownerCallbackNodes[i];
|
||||
|
||||
callbackNode.setCallback(owner[callbackName], owner);
|
||||
}
|
||||
|
||||
// Variables
|
||||
var ownerOutletNames = reader.getOwnerOutletNames();
|
||||
var ownerOutletNodes = reader.getOwnerOutletNodes();
|
||||
|
||||
for (var i = 0; i < ownerOutletNames.length; i++)
|
||||
{
|
||||
var outletName = ownerOutletNames[i];
|
||||
var outletNode = ownerOutletNodes[i];
|
||||
|
||||
owner[outletName] = outletNode;
|
||||
}
|
||||
}
|
||||
|
||||
var nodesWithAnimationManagers = reader.getNodesWithAnimationManagers();
|
||||
var animationManagersForNodes = reader.getAnimationManagersForNodes();
|
||||
|
||||
// Attach animation managers to nodes and assign root node callbacks and member variables
|
||||
for (var i = 0; i < nodesWithAnimationManagers.length; i++)
|
||||
{
|
||||
var innerNode = nodesWithAnimationManagers[i];
|
||||
var animationManager = animationManagersForNodes[i];
|
||||
|
||||
innerNode.animationManager = animationManager;
|
||||
|
||||
var documentControllerName = animationManager.getDocumentControllerName();
|
||||
if (!documentControllerName) continue;
|
||||
|
||||
// Create a document controller
|
||||
var controller = new _ccbGlobalContext[documentControllerName]();
|
||||
controller.controllerName = documentControllerName;
|
||||
|
||||
innerNode.controller = controller;
|
||||
controller.rootNode = innerNode;
|
||||
|
||||
// Callbacks
|
||||
var documentCallbackNames = animationManager.getDocumentCallbackNames();
|
||||
var documentCallbackNodes = animationManager.getDocumentCallbackNodes();
|
||||
|
||||
for (var j = 0; j < documentCallbackNames.length; j++)
|
||||
{
|
||||
var callbackName = documentCallbackNames[j];
|
||||
var callbackNode = documentCallbackNodes[j];
|
||||
|
||||
callbackNode.setCallback(controller[callbackName], controller);
|
||||
}
|
||||
|
||||
|
||||
// Variables
|
||||
var documentOutletNames = animationManager.getDocumentOutletNames();
|
||||
var documentOutletNodes = animationManager.getDocumentOutletNodes();
|
||||
|
||||
for (var j = 0; j < documentOutletNames.length; j++)
|
||||
{
|
||||
var outletName = documentOutletNames[j];
|
||||
var outletNode = documentOutletNodes[j];
|
||||
|
||||
controller[outletName] = outletNode;
|
||||
}
|
||||
|
||||
if (typeof(controller.onDidLoadFromCCB) == "function")
|
||||
{
|
||||
controller.onDidLoadFromCCB();
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
cc.Reader.loadAsScene = function(file, owner, parentSize)
|
||||
{
|
||||
var node = cc.Reader.load(file, owner, parentSize);
|
||||
var scene = cc.Scene.create();
|
||||
scene.addChild( node );
|
||||
|
||||
return scene;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// OpenGL defines
|
||||
//
|
||||
|
||||
var gl = gl || {};
|
||||
gl.NEAREST = 0x2600;
|
||||
gl.LINEAR = 0x2601;
|
||||
gl.REPEAT = 0x2901;
|
||||
gl.CLAMP_TO_EDGE = 0x812F;
|
||||
gl.CLAMP_TO_BORDER = 0x812D;
|
||||
gl.LINEAR_MIPMAP_NEAREST = 0x2701;
|
||||
gl.NEAREST_MIPMAP_NEAREST = 0x2700;
|
||||
gl.ZERO = 0;
|
||||
gl.ONE = 1;
|
||||
gl.SRC_COLOR = 0x0300;
|
||||
gl.ONE_MINUS_SRC_COLOR = 0x0301;
|
||||
gl.SRC_ALPHA = 0x0302;
|
||||
gl.ONE_MINUS_SRC_ALPHA = 0x0303;
|
||||
gl.DST_ALPHA = 0x0304;
|
||||
gl.ONE_MINUS_DST_ALPHA = 0x0305;
|
||||
gl.DST_COLOR = 0x0306;
|
||||
gl.ONE_MINUS_DST_COLOR = 0x0307;
|
||||
gl.SRC_ALPHA_SATURATE = 0x0308;
|
Loading…
Reference in New Issue