在HelloWorld上--建立新情境

來源:互聯網
上載者:User

添加新檔案 

命名為:CMyFirstScene,

.CPP和.h 檔案分別填上以下內容

 
  1. //
  2. // CMyFirstScene.cpp
  3. // linker
  4. //
  5. // Created by HeJiasheng on 14-3-12.
  6. //
  7. //
  8. #include "CMyFirstScene.h"
  9. USING_NS_CC;
  10. Scene* CMyFirstScene::createScene()
  11. {
  12. // 'scene' is an autorelease object
  13. auto scene = Scene::create();
  14. // 'layer' is an autorelease object
  15. auto layer = CMyFirstScene::create();
  16. // add layer as a child to scene
  17. scene->addChild(layer);
  18. // return the scene
  19. return scene;
  20. }
  21. bool CMyFirstScene::init()
  22. {
  23. if(!CCLayer::init())
  24. {
  25. return false;
  26. }
  27. auto label = LabelTTF::create("New Scene", "Arial", 24);
  28. // position the label on the center of the screen
  29. label->setPosition(Point(200,300));
  30. // add the label as a child to this layer
  31. this->addChild(label, 1);
  32. // do something
  33. return true;
  34. }
 
  1. #ifndef __linker__CMyFirstScene__
  2. #define __linker__CMyFirstScene__
  3. #include "cocos2d.h"
  4. class CMyFirstScene : public cocos2d::CCLayer
  5. {
  6. public:
  7. static cocos2d::Scene* createScene();
  8. // 初始化
  9. virtual bool init();
  10. CREATE_FUNC(CMyFirstScene);
  11. };
  12. #endif /* defined(__linker__CMyFirstScene__) */

在 HelloWorld.cpp 回呼函數添加如下:

 
  1. void HelloWorld::imageMenuCallback(Object* pSender)
  2. {
  3. CCLog("ImageMenu");
  4. CCTransitionScene* transiton =CCTransitionProgressRadialCW::create(1.2f, CMyFirstScene::createScene());
  5. CCDirector::sharedDirector()->replaceScene(transiton);
  6. }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.