小子新手,最近才接触COCOS2D-X,希望能得到指教。
问题:
我在用CCSprite* white_bg=CCSprite::create(“white_bg.png”);加载一张背景图的时候出现下列问题:
-> PushBox.exe (项目名是PushBox)中的 0x00fa22a0 处有未经处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突
代码如下:
#include “HelloWorldScene.h”
#include “SimpleAudioEngine.h”
USING_NS_CC;
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
//预加载背景音乐与播放背景音乐;
CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(“music.mp3”);
CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(“music.mp3”, true);
//加载界面背景;
CCSprite* white_bg=CCSprite::create(“white_bg.png”);
white_bg->setAnchorPoint(ccp(0,0.5));
white_bg->setPosition(ccp(240,160));
this->addChild(white_bg);
//加载cute人物;
CCSprite* cute=CCSprite::create(“cute.png”);
cute->setAnchorPoint(ccp(0.5,0.5));
cute->setPosition(ccp(140,160));
this->addChild(cute);
return true;
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox(“You pressed the close button. Windows Store Apps do not implement a close button.”,“Alert”);
#else
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
#endif
}