资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

cocos2d场景切换-创新互联

开始学习cocos2d啦,加油啊!!!

站在用户的角度思考问题,与客户深入沟通,找到沅陵网站设计与沅陵网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都做网站、网站建设、外贸营销网站建设、企业官网、英文网站、手机端网站、网站推广、域名注册、虚拟空间、企业邮箱。业务覆盖沅陵地区。

第一个hello world界面

#ifndef __HELLOWORLD_SCENE_H__

#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"

#include "SimpleAudioEngine.h"

class HelloWorld : public cocos2d::CCLayer

{

public:

  // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone

  virtual bool init();

  // there's no 'id' in cpp, so we recommand to return the exactly class pointer

  static cocos2d::CCScene* scene();

  // a selector callback

  void menuCloseCallback(CCObject* pSender);

  // implement the "static node()" method manually

  CREATE_FUNC(HelloWorld);

};

#endif  // __HELLOWORLD_SCENE_H__

#include "HelloWorldScene.h"

#include "MyLayer.h"

using namespace cocos2d;

CCScene* HelloWorld::scene()

{

  CCScene * scene = NULL;

  do

  {

    // 'scene' is an autorelease object

    scene = CCScene::create();

    CC_BREAK_IF(! scene);

    // 'layer' is an autorelease object

    HelloWorld *layer = HelloWorld::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 HelloWorld::init()

{

  bool bRet = false;

  do

  {

    //////////////////////////////////////////////////////////////////////////

    // super init first

    //////////////////////////////////////////////////////////////////////////

    CC_BREAK_IF(! CCLayer::init());

    //////////////////////////////////////////////////////////////////////////

    // add your codes below...

    //////////////////////////////////////////////////////////////////////////

    // 1. Add a menu item with "X" p_w_picpath, which is clicked to quit the program.

    // Create a "close" menu item with close icon, it's an auto release object.

    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(

      "CloseNormal.png",

      "CloseSelected.png",

      this,

      menu_selector(HelloWorld::menuCloseCallback));

    CC_BREAK_IF(! pCloseItem);

    // Place the menu item bottom-right conner.

    pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));

    // Create a menu with the "close" menu item, it's an auto release object.

    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);

    pMenu->setPosition(CCPointZero);

    CC_BREAK_IF(! pMenu);

    // Add the menu to HelloWorld layer as a child layer.

    this->addChild(pMenu, 1);

    // 2. Add a label shows "Hello World".

    // Create a label and initialize with string "Hello World".

    CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);

    CC_BREAK_IF(! pLabel);

    // Get window size and place the label upper.

    CCSize size = CCDirector::sharedDirector()->getWinSize();

    pLabel->setPosition(ccp(size.width / 2, size.height - 50));

    // Add the label to HelloWorld layer as a child layer.

    this->addChild(pLabel, 1);

    // 3. Add add a splash screen, show the cocos2d splash p_w_picpath.

    CCSprite* pSprite = CCSprite::create("HelloWorld.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 HelloWorld::menuCloseCallback(CCObject* pSender)

{

  // "close" menu item clicked

  // CCDirector::sharedDirector()->end();

//场景切换

CCDirector::sharedDirector()->replaceScene(CCTransitionSlideInT::create(3.0,CMyLayer::scence()));

}

第二个场景代码

#pragma once

#include "cocos2d.h"

using namespace cocos2d;

class CMyLayer:public CCLayer

{

public:

CMyLayer(void);

~CMyLayer(void);

static CCScene * scence();

virtual bool init();

void CMyLayer::menuCloseCallback(CCObject* pSender);

CREATE_FUNC(CMyLayer);

};

#include "MyLayer.h"

CMyLayer::CMyLayer(void)

{

}

CMyLayer::~CMyLayer(void)

{

}

 CCScene *CMyLayer:: scence()

{

CCScene *pScence = CCScene::create();

CMyLayer *pCMyLayer = CMyLayer::create();

pScence->addChild(pCMyLayer);

return pScence;

}

bool CMyLayer::  init()

{

CCLabelTTF *pLable = CCLabelTTF::create("HI Fighting..!!!","Arial",40);

pLable->setPosition(ccp(200,200));

this->addChild(pLable);

CCMenuItemImage *pCloseItem = CCMenuItemImage::create(

"CloseNormal.png",

"CloseSelected.png",

this,

menu_selector(CMyLayer::menuCloseCallback));

//CC_BREAK_IF(! pCloseItem);

// Place the menu item bottom-right conner.

pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));

// Create a menu with the "close" menu item, it's an auto release object.

CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);

pMenu->setPosition(CCPointZero);

 this->addChild(pMenu, 1);

//CC_BREAK_IF(! pMenu);

return true;

}

void CMyLayer::menuCloseCallback(CCObject* pSender)

{

// "close" menu item clicked

CCDirector::sharedDirector()->end();

//CCDirector::sharedDirector()->replaceScene(CMyLayer::scence());

}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站栏目:cocos2d场景切换-创新互联
文章源于:http://cdkjz.cn/article/dpjgdg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220