小白一枚,按照教程在CocoStudio上制作了一個游戲的初始場景,然后在VS2015的專案上修改了代碼,想要替換HelloWorld的畫面,也就是在vs上匯入.csb檔案,修改代碼后,程式可運行,但是是黑屏的,畫面并不能正常顯示。找了很多辦法,始終沒有解決,請大神指點一下,告訴一下解決方法吧,謝謝!

這是代碼
h檔案
#pragma once
#ifndef __Login_SCENE_H__
#define __Login_SCENE_H__
#include "cocos2d.h"
class Login : public cocos2d::Layer
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
};
CREATE_FUNC(Login);
#endif // __Login_SCENE_H__
cpp檔案
#include "LoginScene.h"
#include "SimpleAudioEngine.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
USING_NS_CC;
using namespace cocostudio::timeline;
Scene* Login::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = Login::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool Login::init()
{
//////////////////////////////
// 1. super init first
if (!Layer::init())
{
return false;
}
auto pNode = CSLoader::createNode("MainScene.csb");
auto rootNode = CSLoader::createNode("LoginScene.csb");
this->addChild(pNode);
this->addChild(rootNode);
return true;
}
void Login::menuCloseCallback(Ref* pSender)
{
//Close the cocos2d-x game scene and quit the application
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
/*To navigate back to native iOS screen(if present) without quitting the application ,do not use Director::getInstance()->end() and exit(0) as given above,instead trigger a custom event created in RootViewController.mm as below*/
//EventCustom customEndEvent("game_scene_close_event");
//_eventDispatcher->dispatchEvent(&customEndEvent);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/130005.html
標籤:Cocos2d-x
上一篇:lua中怎么控制 Poptip.PopMsg的顯示數目
下一篇:NGUI上加的粒子特效被遮擋
