如何创建android cocos2dx闪屏?
这是我的代码,我不知道如何创建启动屏幕,它将如何在我的菜单屏幕直接。所有.h必须连接到BaseScreen,并且BaseScreen将是在cocos2d层中连接的。请帮我输入密码。唯一出现在模拟器中的是我在HelloWorldScreen.h中编写的精灵 SplashScreen.h如何创建android cocos2dx闪屏?,android,cocos2d-x,splash-screen,scene,Android,Cocos2d X,Splash Screen,Scene,这是我的代码,我不知道如何创建启动屏幕,它将如何在我的菜单屏幕直接。所有.h必须连接到BaseScreen,并且BaseScreen将是在cocos2d层中连接的。请帮我输入密码。唯一出现在模拟器中的是我在HelloWorldScreen.h中编写的精灵 SplashScreen.h ifndef __SPLASH_SCREEN_H__ define __SPLASH_SCREEN_H__ include "BaseScreen.h" include "cocos2d.h" class Sp
ifndef __SPLASH_SCREEN_H__
define __SPLASH_SCREEN_H__
include "BaseScreen.h"
include "cocos2d.h"
class SplashScreen : BaseScreen
{
public:
void update ();
static cocos2d::CCSprite* splashScreen;
int time;
MenuScreen menuScreen;
};
endif
ifndef __BASE_SCREEN_H__
define __BASE_SCREEN_H__
include "cocos2d.h"
class BaseScreen : public cocos2d::CCLayer
{
public:
// BaseScreen getParent ();
void loadNewScreen (BaseScreen newScreen);
void update ();
// BaseScreen *parentBaseScene;
};
endif
#ifndef __SplashScene__
#define __SplashScene__
#include <stdio.h>
#include "cocos2d.h"
USING_NS_CC;
class SplashScene : public cocos2d::Layer
{
public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
void onEnter();
void finishSplash(float dt);
// implement the "static create()" method manually
CREATE_FUNC(SplashScene);
};
#endif /* defined(__stickerPuzzle__SplashScene__) */
HelloWorldScene.cpp
include "HelloWorldScene.h"
include "SplashScreen.h"
include "cocos2d.h"
USING_NS_CC;
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::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 HelloWorld::init()
{
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
origin.y + pCloseItem->getContentSize().height/2));
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
// 3. add your codes below...
// create background image from png
CCSprite *splashScreen = CCSprite::create("company.png");
// position the background image at the center of window
splashScreen->setPosition(ccp(size.width / 2, size.height / 2));
// add background image at z-position = -1, bottom of all
this->addChild(splashScreen, -1);
// calculate the scaling factor to fill the window size
float bX = size.width / splashScreen->getContentSize().width;
float bY = size.height / splashScreen->getContentSize().height;
// set the scaling factor to the background image
splashScreen->setScaleX(bX);
splashScreen->setScaleY(bY);
return true;
}
//callfuncN_selector(MainScene::spriteMoveFinished)
//backcalls the function spriteMoveFinished()
void HelloWorld::spriteMoveFinished(CCNode* pSender)
{
CCSprite *sprite = (CCSprite *)pSender;
this->removeChild(sprite, true);
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->end();
if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
endif
}
#include "SplashScene.h"
#include "HomeScene.h"
using namespace cocos2d;
cocos2d::Scene* SplashScene::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = SplashScene::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 SplashScene::init()
{
if ( !Layer::init() )
{
return false;
}
auto visibleSize = Director::getInstance()->getVisibleSize();
auto sprite = Sprite::create("splash.png");
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 , visibleSize.height/2 ));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
return true;
}
void SplashScene::onEnter() {
Layer::onEnter();
// Wait for 0.5 seconds to load main scene
this->scheduleOnce(schedule_selector(SplashScene::finishSplash), 0.5f);
}
void SplashScene::finishSplash(float dt) {
// ... do whatever other initializations here
// Show the actual main scene
Director::getInstance()->replaceScene(HomeScene::createScene());
}
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLViewImpl::create("My Game");
director->setOpenGLView(glview);
}
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);
// ... other stuff ...
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// On Android - start the splash scene first
auto scene = SplashScene::createScene();
director->runWithScene(scene);
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// On iOS, no need to add splash scene, start main scene directly
auto scene = HomeScene::createScene();
director->runWithScene(scene);
#endif
return true;
}
BaseScreen.h
ifndef __SPLASH_SCREEN_H__
define __SPLASH_SCREEN_H__
include "BaseScreen.h"
include "cocos2d.h"
class SplashScreen : BaseScreen
{
public:
void update ();
static cocos2d::CCSprite* splashScreen;
int time;
MenuScreen menuScreen;
};
endif
ifndef __BASE_SCREEN_H__
define __BASE_SCREEN_H__
include "cocos2d.h"
class BaseScreen : public cocos2d::CCLayer
{
public:
// BaseScreen getParent ();
void loadNewScreen (BaseScreen newScreen);
void update ();
// BaseScreen *parentBaseScene;
};
endif
#ifndef __SplashScene__
#define __SplashScene__
#include <stdio.h>
#include "cocos2d.h"
USING_NS_CC;
class SplashScene : public cocos2d::Layer
{
public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
void onEnter();
void finishSplash(float dt);
// implement the "static create()" method manually
CREATE_FUNC(SplashScene);
};
#endif /* defined(__stickerPuzzle__SplashScene__) */
试试这个链接,也许你可以在这里找到一些有用的东西
或者试试这个,我希望它能解决这个问题。你可以让类从CCLayer继承,它可以启动你的应用程序并显示你的精灵。然后可以重写OnInterTransitiondFinish方法:
void SplashScreen::onEnterTransitionDidFinish(){
CCScene * sceneAfterSplashScreen = StartLayer::scene();
CCDirector::sharedDirector()->replaceScene(sceneAfterSplashScreen);
}
当启动屏幕到达屏幕时,它开始加载新场景并替换它。我正在使用
scheduleOnce
功能
void Splash::onEnter(){
CCLayer::onEnter();
CCLog("onEnter");
this->scheduleOnce(schedule_selector(Splash::finishSplash),2.0f);
}
void Splash::finishSplash(float dt){
CCDirector::sharedDirector()->replaceScene(GameWall::scene());
}
2秒后,完成启动屏幕并启动GameWall屏幕。这就是我所做的。以下是在android上添加闪屏场景的三个步骤。使用cocos2d-x 3.4。希望这有帮助 1创建一个场景。cpp
include "HelloWorldScene.h"
include "SplashScreen.h"
include "cocos2d.h"
USING_NS_CC;
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::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 HelloWorld::init()
{
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
origin.y + pCloseItem->getContentSize().height/2));
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
// 3. add your codes below...
// create background image from png
CCSprite *splashScreen = CCSprite::create("company.png");
// position the background image at the center of window
splashScreen->setPosition(ccp(size.width / 2, size.height / 2));
// add background image at z-position = -1, bottom of all
this->addChild(splashScreen, -1);
// calculate the scaling factor to fill the window size
float bX = size.width / splashScreen->getContentSize().width;
float bY = size.height / splashScreen->getContentSize().height;
// set the scaling factor to the background image
splashScreen->setScaleX(bX);
splashScreen->setScaleY(bY);
return true;
}
//callfuncN_selector(MainScene::spriteMoveFinished)
//backcalls the function spriteMoveFinished()
void HelloWorld::spriteMoveFinished(CCNode* pSender)
{
CCSprite *sprite = (CCSprite *)pSender;
this->removeChild(sprite, true);
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->end();
if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
endif
}
#include "SplashScene.h"
#include "HomeScene.h"
using namespace cocos2d;
cocos2d::Scene* SplashScene::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = SplashScene::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 SplashScene::init()
{
if ( !Layer::init() )
{
return false;
}
auto visibleSize = Director::getInstance()->getVisibleSize();
auto sprite = Sprite::create("splash.png");
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 , visibleSize.height/2 ));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
return true;
}
void SplashScene::onEnter() {
Layer::onEnter();
// Wait for 0.5 seconds to load main scene
this->scheduleOnce(schedule_selector(SplashScene::finishSplash), 0.5f);
}
void SplashScene::finishSplash(float dt) {
// ... do whatever other initializations here
// Show the actual main scene
Director::getInstance()->replaceScene(HomeScene::createScene());
}
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLViewImpl::create("My Game");
director->setOpenGLView(glview);
}
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);
// ... other stuff ...
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// On Android - start the splash scene first
auto scene = SplashScene::createScene();
director->runWithScene(scene);
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// On iOS, no need to add splash scene, start main scene directly
auto scene = HomeScene::createScene();
director->runWithScene(scene);
#endif
return true;
}
2创建SplashScene.h
ifndef __SPLASH_SCREEN_H__
define __SPLASH_SCREEN_H__
include "BaseScreen.h"
include "cocos2d.h"
class SplashScreen : BaseScreen
{
public:
void update ();
static cocos2d::CCSprite* splashScreen;
int time;
MenuScreen menuScreen;
};
endif
ifndef __BASE_SCREEN_H__
define __BASE_SCREEN_H__
include "cocos2d.h"
class BaseScreen : public cocos2d::CCLayer
{
public:
// BaseScreen getParent ();
void loadNewScreen (BaseScreen newScreen);
void update ();
// BaseScreen *parentBaseScene;
};
endif
#ifndef __SplashScene__
#define __SplashScene__
#include <stdio.h>
#include "cocos2d.h"
USING_NS_CC;
class SplashScene : public cocos2d::Layer
{
public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
void onEnter();
void finishSplash(float dt);
// implement the "static create()" method manually
CREATE_FUNC(SplashScene);
};
#endif /* defined(__stickerPuzzle__SplashScene__) */
你是为iOS还是Android开发的?我是为cocos2dxuhm开发的Android游戏你有任何链接是为cocos2dx开发的闪屏吗?谢谢你的链接,有没有已经制作好的带有闪屏的游戏可以免费下载其源代码?好的,那么我的类HelloWorldScene可以是那个类吗?我会把这些代码放在那里,对吗?谢谢你的回答,我会试试这个,然后我把你的代码放到我的HelloWorldScene类中,然后我把void------->onentertTransitiondFinish();然后在HelloWorldScene.h中创建错误:重写cocos2d::CclayeronEnterTransitiondFinish和错误:在类“HelloWorld”中声明的成员函数“void HelloWorld::OneInterTransitiondFinish()”。我是一个新手,所以我很难理解请帮助谢谢你的回复我用这一行代码完成了初始屏幕CCDirector::sharedDirector()->ReplaceSecene(CCTransitionFade::create(3.0f,MenuScene::scene());