mirror of https://github.com/axmolengine/axmol.git
Adding sample game wrapper using CCBReader. Also includes small modification to CCBReader
This commit is contained in:
parent
bc35e73179
commit
100a7a1883
|
@ -3,7 +3,7 @@
|
|||
#define __CCB_CCDATA_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocos-ext.h"
|
||||
#include "ExtensionMacros.h""
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
|
|
|
@ -13,10 +13,19 @@
|
|||
USING_NS_CC;
|
||||
USING_NS_CC_EXT;
|
||||
|
||||
static void removeSelector(std::string &str) {
|
||||
size_t found;
|
||||
found = str.find(":");
|
||||
while (found!=std::string::npos){
|
||||
str.replace(found, found+1, "");
|
||||
found = str.find(":");
|
||||
}
|
||||
}
|
||||
|
||||
SEL_MenuHandler CCBScriptCallbackProxy::onResolveCCBCCMenuItemSelector(cocos2d::CCObject * pTarget,
|
||||
cocos2d::CCString * pSelectorName) {
|
||||
this->callBackProp = pSelectorName->getCString();
|
||||
removeSelector(this->callBackProp);
|
||||
return menu_selector(CCBScriptCallbackProxy::menuItemCallback);
|
||||
}
|
||||
|
||||
|
@ -24,12 +33,14 @@ SEL_CCControlHandler CCBScriptCallbackProxy::onResolveCCBCCControlSelector(CCObj
|
|||
CCString * pSelectorName) {
|
||||
|
||||
this->callBackProp = pSelectorName->getCString();
|
||||
removeSelector(this->callBackProp);
|
||||
return cccontrol_selector(CCBScriptCallbackProxy::controlCallback);
|
||||
}
|
||||
|
||||
bool CCBScriptCallbackProxy::onAssignCCBMemberVariable(CCObject * pTarget,
|
||||
CCString * pMemberVariableName,
|
||||
CCNode * pNode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCBScriptCallbackProxy::onNodeLoaded(CCNode * pNode,
|
||||
|
@ -81,11 +92,8 @@ static CCNode* loadReader(const char *file, jsval owner) {
|
|||
//ccbReader->setOwner(dynamic_cast<CCObject *>(ccBCallbackProxy));
|
||||
|
||||
CCBSelectorResolver * targetAsCCBSelectorResolver = dynamic_cast<CCBSelectorResolver *>(ccBCallbackProxy);
|
||||
if(targetAsCCBSelectorResolver != NULL) {
|
||||
js_log("NOT NULL");
|
||||
}
|
||||
|
||||
CCNode * node = ccbReader->readNodeGraphFromFile("./", file, dynamic_cast<CCObject *>(ccBCallbackProxy));
|
||||
CCNode * node = ccbReader->readNodeGraphFromFile(file, dynamic_cast<CCObject *>(ccBCallbackProxy));
|
||||
|
||||
return node;
|
||||
}
|
||||
|
|
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/Abadi40-hd.png.REMOVED.git-id
vendored
Normal file
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/Abadi40-hd.png.REMOVED.git-id
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
f06c047dd32b61f12ad51e981afe518364512be6
|
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/Abadi40-ipad.png.REMOVED.git-id
vendored
Normal file
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/Abadi40-ipad.png.REMOVED.git-id
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
4b7c1e97acefff48ae3652f023e708245992f553
|
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/Abadi40.png.REMOVED.git-id
vendored
Normal file
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/Abadi40.png.REMOVED.git-id
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
ae62d7b07ac3e7579ed7d6a2e1f903719e45c6d9
|
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/Gas40-hd.png.REMOVED.git-id
vendored
Normal file
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/Gas40-hd.png.REMOVED.git-id
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
12db20c3124e1bd864312257eb8cefe95d2ee349
|
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/Gas40-ipad.png.REMOVED.git-id
vendored
Normal file
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/Gas40-ipad.png.REMOVED.git-id
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
e71140c1535f16b49980f3ea0cf7d3a29a8a9788
|
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/konqa32-hd.png.REMOVED.git-id
vendored
Normal file
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/konqa32-hd.png.REMOVED.git-id
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
dc235c169030151e337ecbfa1fc6302fc909e500
|
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/konqa32-ipad.png.REMOVED.git-id
vendored
Normal file
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/konqa32-ipad.png.REMOVED.git-id
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
9e95a02e6eb2944fea12a49eb3f2c6fe7505a3ce
|
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/konqa32.png.REMOVED.git-id
vendored
Normal file
1
template/xcode4/cocos2dx_js.xctemplate/Resources/CCB/konqa32.png.REMOVED.git-id
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
1423c81273926b3da9fb1cb36c9b710d3f14ee0e
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
try {
|
||||
|
||||
cc.p = cc.p || function( x, y ) {
|
||||
|
@ -8,8 +9,23 @@ try {
|
|||
return {r: r, g: g, b: b, a: o};
|
||||
};
|
||||
|
||||
|
||||
cc.c3 = cc.c3 || function (r, g, b) {
|
||||
return {r: r, g: g, b: b};
|
||||
};
|
||||
cc.BLACK = cc.c3(0,0,0);
|
||||
|
||||
|
||||
director = cc.Director.getInstance();
|
||||
winSize = director.getWinSize();
|
||||
centerPos = cc.p( winSize.width/2, winSize.height/2 );
|
||||
|
||||
var GameCreator = function() {
|
||||
|
||||
var self = {};
|
||||
self.callbacks = {};
|
||||
|
||||
self.getPlayScene = function() {
|
||||
|
||||
var scene = new cc.Scene();
|
||||
var layer = new cc.LayerGradient();
|
||||
|
@ -21,9 +37,111 @@ try {
|
|||
layer.addChild(label, 1);
|
||||
label.setPosition( cc.p(winSize.width / 2, winSize.height / 2));
|
||||
|
||||
var back = cc.MenuItemFont.create("Back", this.callbacks, this.callbacks.onBack );
|
||||
back.setColor( cc.BLACK );
|
||||
|
||||
var menu = cc.Menu.create( back );
|
||||
layer.addChild( menu );
|
||||
menu.alignItemsVertically();
|
||||
menu.setPosition( cc.p( winSize.width - 50, 50) );
|
||||
|
||||
scene.addChild(layer);
|
||||
|
||||
director.runWithScene(scene);
|
||||
return scene;
|
||||
};
|
||||
|
||||
self.getMainMenuScene = function() {
|
||||
var l = cc.Layer.create();
|
||||
var scene = cc.Scene.create();
|
||||
|
||||
var node = cc.Reader.load("MainMenu.ccbi", this, winSize);
|
||||
l.addChild(node);
|
||||
|
||||
scene.addChild(l);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
self.getOptionsScene = function() {
|
||||
|
||||
var l = cc.LayerGradient.create();
|
||||
l.init(cc.c4b(0, 0, 0, 255), cc.c4b(255, 255, 255, 255));
|
||||
|
||||
var scene = cc.Scene.create();
|
||||
|
||||
var label1 = cc.LabelBMFont.create("MUSIC ON", "konqa32.fnt" );
|
||||
var item1 = cc.MenuItemLabel.create(label1);
|
||||
var label2 = cc.LabelBMFont.create("MUSIC OFF", "konqa32.fnt" );
|
||||
var item2 = cc.MenuItemLabel.create(label2);
|
||||
var toggle = cc.MenuItemToggle.create( item1, item2 );
|
||||
|
||||
this.onMusicToggle = function( sender ) {
|
||||
};
|
||||
|
||||
toggle.setCallback( this, this.onMusicToggle);
|
||||
|
||||
var back = cc.MenuItemFont.create("Back", this.callbacks, this.callbacks.onBack );
|
||||
var menu = cc.Menu.create( toggle, back );
|
||||
l.addChild( menu );
|
||||
menu.alignItemsVertically();
|
||||
menu.setPosition( centerPos );
|
||||
|
||||
scene.addChild(l);
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
|
||||
self.getAboutScene = function() {
|
||||
|
||||
var scene = cc.Scene.create();
|
||||
var l = cc.Layer.create();
|
||||
var about = cc.Reader.load("About.ccbi", this);
|
||||
l.addChild( about )
|
||||
|
||||
var back = cc.MenuItemFont.create("Back", this.callbacks, this.callbacks.onBack );
|
||||
back.setColor( cc.BLACK );
|
||||
var menu = cc.Menu.create( back );
|
||||
l.addChild( menu );
|
||||
menu.alignItemsVertically();
|
||||
menu.setPosition( cc.p( winSize.width - 50, 50) );
|
||||
|
||||
scene.addChild( l );
|
||||
|
||||
return scene;
|
||||
};
|
||||
|
||||
|
||||
// CCBuilder Selectors
|
||||
|
||||
self.onPlay = function() {
|
||||
director.replaceScene( cc.TransitionFade.create(1, this.getPlayScene()) );
|
||||
}
|
||||
|
||||
self.onAbout = function() {
|
||||
director.replaceScene( cc.TransitionZoomFlipY.create(1, this.getAboutScene()) );
|
||||
};
|
||||
|
||||
self.onOptions = function() {
|
||||
director.replaceScene( cc.TransitionZoomFlipY.create(1, this.getOptionsScene()) );
|
||||
};
|
||||
|
||||
|
||||
// Manual Callbacks
|
||||
|
||||
self.callbacks.onBack = function( sender) {
|
||||
director.replaceScene( cc.TransitionFlipX.create(1, self.getMainMenuScene()) );
|
||||
};
|
||||
|
||||
return self;
|
||||
|
||||
};
|
||||
|
||||
var game = GameCreator();
|
||||
|
||||
__jsc__.garbageCollect();
|
||||
|
||||
director.runWithScene(game.getMainMenuScene());
|
||||
|
||||
} catch(e) {log(e);}
|
||||
|
||||
|
|
Loading…
Reference in New Issue