zoukankan      html  css  js  c++  java
  • cocos2d-x项目101次相遇:在HelloWorld上--建立新场景

    • cocos2d-x 101次相遇 / 文件夹 
      1   安装和环境搭建 -xcode 
      2   Scenes , Director, Layers, Sprites
      3   建立图片菜单 
      4   在HelloWorld上--建立新场景 
      5   添加一个精灵sprite 
      5.1   缩小sprite并使之完整显示
      6   action ,移动sprite 
      7   3.0 的点击事件,CCTouchDelegate已经停用了
      8   使用触摸事件移动 精灵

    4   在HelloWorld上--建立新场景

    加入新文件 266dd5b6a9ec11e3b746f23c91693c1b.png

    命名为: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. 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. // 初始化

    9. virtualbool init();

    10.    CREATE_FUNC(CMyFirstScene);

    11. };

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

    在 HelloWorld.cpp 回调函数加入例如以下:

    
    
    1. voidHelloWorld::imageMenuCallback(Object* pSender)

    2. {

    3. CCLog("ImageMenu");

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

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

    6. }

  • 相关阅读:
    获取MySQL各版本yum源 并安装
    CentOS 防火墙实用操作
    简单3步将你的python转成exe格式
    java 实现扑克牌打印
    java 一维数组的总结笔记
    java中如何理解:其他类型 + string 与 自增类型转换和赋值类型转换
    c语言 0与非0
    Python中nonlocal的用法
    Python基础系列讲解-自动控制windows桌面
    flask_caching 缓存
  • 原文地址:https://www.cnblogs.com/lytwajue/p/6832256.html
Copyright © 2011-2022 走看看