请教一个不使用cocosbuilder 的js controlled功能时的问题
1个回答
推荐于2016-11-10
展开全部
cpp文件:
//
// MainScene.cpp
// cpp_project_002
//
// Created by 123 on 13-11-5.
//
//
#include "MainScene.h"
USING_NS_CC;
USING_NS_CC_EXT;
CCScene* MainScene::scene()
{
CCScene *scene = CCScene::create();
CCNodeLoaderLibrary *lib = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary(); //生成一个默认的Node Loader
CCBReader *reader = new CCBReader(lib); //用node load lib 初始化一个ccb reader
CCNode *node = reader->readNodeGraphFromFile("MainScene.ccbi", scene); //从ccbi文件中加载node
reader->release(); //注意手动释放内存
if (node!=NULL)
{
scene->addChild(node); //将node 添加到scene中
}
CCLog("scene create success");
return scene;
}
void MainScene::onPressBt(cocos2d::CCObject *pSender){
CCLog("onPressButton");
}
.h文件:
//
// MainScene.h
// cpp_project_002
//
// Created by 123 on 13-11-5.
//
//
#ifndef cpp_project_002_MainScene_h
#define cpp_project_002_MainScene_h
#include "cocos2d.h"
#include "cocos-ext.h"
class MainScene: public cocos2d::CCLayer,public cocos2d::extension::CCLayerLoader
{
public:
static cocos2d::CCScene* scene();
void onPressBt(cocos2d::CCObject *pSender);
};
//
// MainScene.cpp
// cpp_project_002
//
// Created by 123 on 13-11-5.
//
//
#include "MainScene.h"
USING_NS_CC;
USING_NS_CC_EXT;
CCScene* MainScene::scene()
{
CCScene *scene = CCScene::create();
CCNodeLoaderLibrary *lib = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary(); //生成一个默认的Node Loader
CCBReader *reader = new CCBReader(lib); //用node load lib 初始化一个ccb reader
CCNode *node = reader->readNodeGraphFromFile("MainScene.ccbi", scene); //从ccbi文件中加载node
reader->release(); //注意手动释放内存
if (node!=NULL)
{
scene->addChild(node); //将node 添加到scene中
}
CCLog("scene create success");
return scene;
}
void MainScene::onPressBt(cocos2d::CCObject *pSender){
CCLog("onPressButton");
}
.h文件:
//
// MainScene.h
// cpp_project_002
//
// Created by 123 on 13-11-5.
//
//
#ifndef cpp_project_002_MainScene_h
#define cpp_project_002_MainScene_h
#include "cocos2d.h"
#include "cocos-ext.h"
class MainScene: public cocos2d::CCLayer,public cocos2d::extension::CCLayerLoader
{
public:
static cocos2d::CCScene* scene();
void onPressBt(cocos2d::CCObject *pSender);
};
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询