On HelloWorld -- create a new scenario

Source: Internet
Author: User

Add new file

Name: CMyFirstScene,

Fill in the following content in the. CPP and. h files respectively:

 
 
  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. // Initialization
  9. virtual bool init();
  10. CREATE_FUNC(CMyFirstScene);
  11. };
  12. #endif /* defined(__linker__CMyFirstScene__) */

Add the following in the HelloWorld. cpp callback function:

 
 
  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. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.