各位高手,救急啊 面试需要 以下为主要代码(VS2010下)为什么点击“历史记录”按钮就会报错,无法完成场景切换。提前谢谢各位了!!!
10101011
这是AppDelegate.cpp代码/////////////////////////////////////////////
#include “cocos2d.h”
#include “CCEGLView.h”
#include “AppDelegate.h”
#include “StartScene.h”
#include “HistoryScene.h”
#include “SimpleAudioEngine.h”
using namespace CocosDenshion;
USING_NS_CC;
CCScene* AppDelegate::pHistoryScene=NULL;
CCScene* AppDelegate::pStartScene=NULL;
AppDelegate::AppDelegate()
{
}
AppDelegate::~AppDelegate()
{
SimpleAudioEngine::end();
}
bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
// turn on display FPS
//pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don’t call this
pDirector->setAnimationInterval(1.0 / 60);
// create a scene. it’s an autorelease object
pStartScene = StartScene::scene(); // 场景1
pHistoryScene=HistoryScene::scene(); // 场景2
// run
pDirector->runWithScene(pStartScene);
return true;
}
// This function will be called when the app is inactive. When comes a phone call,it’s be invoked too
void AppDelegate::applicationDidEnterBackground()
{
CCDirector::sharedDirector()->stopAnimation();
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->startAnimation();
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
这是StartScene.cpp代码////////////////////////////////////////////
#include “StartScene.h”
#include “AppDelegate.h”
using namespace cocos2d;
CCScene* StartScene::scene()
{
CCScene * scene = NULL;
do
{
// ‘scene’ is an autorelease object
scene = CCScene::create();
CC_BREAK_IF(! scene);
// ‘layer’ is an autorelease object
StartScene layer = StartScene::create();
CC_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
}
// on “init” you need to initialize your instance
bool StartScene::init()
{
bool bRet = false;
do
{
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
CC_BREAK_IF(! CCLayer::init());
//////////////////////////////////////////////////////////////////////////
// add your codes below…
//////////////////////////////////////////////////////////////////////////
// 创建菜单
CCMenu pMenu = CCMenu::create();
pMenu->setPosition(CCPointZero);
CC_BREAK_IF(! pMenu);
// Add the menu to HelloWorld layer as a child layer.
this->addChild(pMenu, 1);
// 创建“历史记录”按钮
CCMenuItemImage *pButtonOfHistory=CCMenuItemImage::create(“HistoryNormal.png”,
“HistroySelected.png”,this,
menu_selector(StartScene::buttonOfHistoryCallback));
CC_BREAK_IF(!pButtonOfHistory);
CCSize size = CCDirector::sharedDirector()->getWinSize();
pButtonOfHistory->setPosition(size.width/3,size.height/3);// 设置位置
pMenu->addChild(pButtonOfHistory);// 加入菜单
// 创建“开始游戏”按钮
CCMenuItemImage pButtonOfStartGame=CCMenuItemImage::create(“StartGameNormal.png”,
“StartGameSelected.png”,this,
menu_selector(StartScene::buttonOfStartGameCallback));
pButtonOfStartGame->setPosition(size.width2/3,size.height/3); // 位置
pMenu->addChild(pButtonOfStartGame); // 加入菜单
// 背景图片
CCSprite* pSprite = CCSprite::create("StartPage.png");
CC_BREAK_IF(! pSprite);
// Place the sprite on the center of the screen
pSprite->setPosition(ccp(size.width/2, size.height/2));
// Add the sprite to HelloWorld layer as a child layer.
this->addChild(pSprite, 0);
bRet = true;
} while (0);
return bRet;
}
void StartScene::buttonOfHistoryCallback(CCObject *pSender){ // 历史按钮响应函数
CCDirector::sharedDirector()->replaceScene(AppDelegate::pHistoryScene);
}
void StartScene::buttonOfStartGameCallback(CCObject *pSender){ // 开始游戏按钮响应函数
}
/////////////////////////////////////////////////////////////
这是HistroyScene.cpp代码 ///////////////////////////////////
#include “HistoryScene.h”
#include “AppDelegate.h”
using namespace cocos2d;
HistoryScene::HistoryScene(void)
{
}
HistoryScene::~HistoryScene(void)
{
}
CCScene* HistoryScene::scene()
{
CCScene * scene = NULL;
do
{
// ‘scene’ is an autorelease object
scene = CCScene::create();
CC_BREAK_IF(! scene);
// ‘layer’ is an autorelease object
HistoryScene *layer = HistoryScene::create();
CC_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
}
// on “init” you need to initialize your instance
bool HistoryScene::init()
{
bool bRet = false;
do
{
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
CC_BREAK_IF(! CCLayer::init());
//////////////////////////////////////////////////////////////////////////
// add your codes below…
//////////////////////////////////////////////////////////////////////////
CCSize size = CCDirector::sharedDirector()->getWinSize();
// 背景图片
CCSprite* pSprite = CCSprite::create(“HistroyBackground.png”);
CC_BREAK_IF(! pSprite);
// Place the sprite on the center of the screen
pSprite->setPosition(ccp(size.width/2, size.height/2));
// Add the sprite to History layer as a child layer.
this->addChild(pSprite, 0);
bRet = true;
} while (0);
return bRet;
}
void HistoryScene::buttonOfHistoryCallback(CCObject *pSender){
}
void HistoryScene::buttonOfStartGameCallback(CCObject *pSender){
}