Cocos2d-x project 101 encounter: On HelloWorld -- creating a new scenario

Source: Internet
Author: User

  • Cocos2d-x 101 encounter/directory
    1. Installation and environment setup-xcode
    2 Scenes, Director, Layers, Sprites
    3. Create an image menu
    4. Create a new scenario on HelloWorld
    5. Add a sprite.
    5.1 scale down sprite and display it completely
    6 action, mobile sprite
    3.0 Click Event, CCTouchDelegate has been disabled
    8 use the touch event mobile genie

4. Create a new scenario on HelloWorld

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. boolCMyFirstScene::init()

  22. {

  23. if(!CCLayer::init())

  24. {

  25. returnfalse;

  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. returntrue;

  34. }

 
  1. #ifndef __linker__CMyFirstScene__

  2. #define __linker__CMyFirstScene__

  3. #include"cocos2d.h"

  4. classCMyFirstScene:public cocos2d::CCLayer

  5. {

  6. public:

  7. static cocos2d::Scene* createScene();

  8. // Initialization

  9. virtualbool init();

  10.    CREATE_FUNC(CMyFirstScene);

  11. };

  12. #endif/* defined(__linker__CMyFirstScene__) */

Add the following in the HelloWorld. cpp callback function:

 
  1. voidHelloWorld::imageMenuCallback(Object* pSender)

  2. {

  3. CCLog("ImageMenu");

  4. CCTransitionScene* transiton=CCTransitionProgressRadialCW::create(1.2f,CMyFirstScene::createScene());

  5. CCDirector::sharedDirector()->replaceScene(transiton);

  6. }

Related Article

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.