zoukankan      html  css  js  c++  java
  • cocos2D中HelloWorldScene.h和HelloWorldScene.cpp

    HelloWorldScene.h

    #ifndef __HELLOWORLD_SCENE_H__
    #define __HELLOWORLD_SCENE_H__
    
    #include "cocos2d.h"
    
    class HelloWorld : public cocos2d::CCLayer
    {
    public:
        
    	// 这里有一个区别。“init”方法在cocos2d-x 返回 bool ,而不是返回“id”在 cocos2d-iphone
        virtual bool init();  
    
     
    	// 没有“id”在cpp,所以我们推荐返回完全类指针
        static cocos2d::CCScene* scene();
        
        // 一个选择器回调
        void menuCloseCallback(CCObject* pSender);
    
        // 手动实现 "static node()" 这个方法
        CREATE_FUNC(HelloWorld);
    };
    
    #endif  // __HELLOWORLD_SCENE_H__


    HelloWorldScene.cpp

    #include "HelloWorldScene.h"
    
    using namespace cocos2d;
    
    CCScene* HelloWorld::scene()
    {
        CCScene * scene = NULL;
        do 
        {
            // “场景”是一个生成自动释放对象
            scene = CCScene::create();
            CC_BREAK_IF(! scene);
    
            // “层”是一个生成自动释放对象
            HelloWorld *layer = HelloWorld::create();
            CC_BREAK_IF(! layer);
    
            // 添加层作为一个孩子到场景
            scene->addChild(layer);
        } while (0);
    
        // 返回现场
        return scene;
    }
    
    // 在“init”你需要初始化您的实例
    bool HelloWorld::init()
    {
        bool bRet = false;
        do 
        {
            //////////////////////////////////////////////////////////////////////////
            // super init first
            //////////////////////////////////////////////////////////////////////////
    
            CC_BREAK_IF(! CCLayer::init());
    
            //////////////////////////////////////////////////////////////////////////
            // 下面添加你的代码……
            //////////////////////////////////////////////////////////////////////////
    
            // 1。添加一个菜单项以“X”的形象,这是点击退出程序。
    
            // 创建一个“close”以关闭图标菜单项目,这是一个自动释放对象。
            CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                "CloseNormal.png",
                "CloseSelected.png",
                this,
                menu_selector(HelloWorld::menuCloseCallback));
            CC_BREAK_IF(! pCloseItem);
    
            // 将菜单项右下角测试
            pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));
    
            // 创建一个菜单,菜单上的“close”菜单项,它是一个自动释放对象。
            CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
            pMenu->setPosition(CCPointZero);
            CC_BREAK_IF(! pMenu);
    
            // 添加菜单HelloWorld层作为一个孩子层。
            this->addChild(pMenu, 1);
    
            // 2。添加一个标签显示“Hello World”。
    
    
            // 创建一个标签和初始化与字符串“Hello World”。
    		// CCLabelTTF只支持系统的字体,或者你自行添加的ttf字体
            CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 30);
            CC_BREAK_IF(! pLabel);
    
            // 得到窗口的大小和位置标签上。
            CCSize size = CCDirector::sharedDirector()->getWinSize();
            pLabel->setPosition(ccp(size.width / 2, size.height - 50));
    
            // 添加标签到HelloWorld层作为一个孩子层。
            this->addChild(pLabel, 1);
    
            // 3。添加添加一个启动画面,显示cocos2d飞溅的形象。
            CCSprite* pSprite = CCSprite::create("snake.png");
    		
    		
            CC_BREAK_IF(! pSprite);
    
            // 把精灵放在在屏幕的中心
            pSprite->setPosition(ccp(size.width/2, size.height/2));
    
            // 加入精灵到HelloWorld层作为一个孩子层。
            this->addChild(pSprite, 0);
    
            bRet = true;
        } while (0);
    
        return bRet;
    }
    
    void HelloWorld::menuCloseCallback(CCObject* pSender)
    {
        // "close" 菜单项点击
        CCDirector::sharedDirector()->end();
    }
    
    

    以上

  • 相关阅读:
    备份
    Ibatis_dataMapper
    查询成绩都大于80分的学生
    删除文件的工具
    从运行中启动收索引擎
    数据库Northwind
    搭建Android开发环境
    数据库知识结构
    数据库MedicineMis_STD
    数据库work
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3098725.html
Copyright © 2011-2022 走看看