zoukankan      html  css  js  c++  java
  • Cocos2d 之FlyBird开发---GameScore类

    |   版权声明:本文为博主原创文章,未经博主允许不得转载。

      这个类主要实现的是,显示历次成绩中的最好成绩。当然我写的这个很简洁,还可以写的更加的丰富。下面贴上代码:

    GameScore.h

    #ifndef _GAME_SCORE_H_
    #define _GAME_SCORE_H_
     
    #include "cocos2d.h"
    USING_NS_CC;
     
    class GameScore : public cocos2d::Layer
    {
    private:
         cocos2d::Sprite* background;
         cocos2d::MenuItemImage* awayItem;
     
    public:
         static cocos2d::Scene* createScene();
         virtual bool init();
         void scoreInterface();
         void goMainInterface(cocos2d::Ref*);
         CREATE_FUNC(GameScore);
    };
     
    #endif // _GAME_SCORE_H_
    

     

    GameScore.cpp

    #include "GameScore.h"
    #include "GameUnit.h"
    #include "MainMenu.h"
    #include "GameData.h"
     
    unit u2;
     
    cocos2d::Scene* GameScore::createScene()
    {
         Scene* scene = Scene::create();
         GameScore* layer = GameScore::create();
         scene->addChild(layer);
         return scene;
    }
     
    bool GameScore::init()
    {
         if (!Layer::init())
         {
                  return false;
         }
     
         this->scoreInterface();
     
         return true;
    }
     
    void GameScore::scoreInterface()
    {
         background = Sprite::create("background/score.png");
         background->setPosition(Vec2(u2.winOrigin().x + u2.winSize().width / 2,
                  u2.winOrigin().y + u2.winSize().height / 2));
         background->setScale(u2.scaleX(background, u2.winSize()),
                  u2.scaleY(background, u2.winSize()));
         this->addChild(background, 0);
     
         awayItem = MenuItemImage::create(
                  "button/away.png",
                  "button/buttom.png",
                  CC_CALLBACK_1(GameScore::goMainInterface, this));
         awayItem->setPosition(Vec2(u2.winOrigin().x + awayItem->getContentSize().width / 2,
                  u2.winOrigin().y + awayItem->getContentSize().height / 2));
         auto m = Menu::create(awayItem, NULL);
         m->setPosition(Vec2::ZERO);
         this->addChild(m, 2);
     
         int bestScore = GameData::getGameData();
         cocos2d::LabelTTF* score = LabelTTF::create("0", "Arial", 26);
         score->setPosition(Vec2(u2.winSize().width / 2,
                  u2.winSize().height / 2));
         this->addChild(score, 4);
         score->setColor(Color3B(0, 0, 0));
         score->setString(__String::createWithFormat("%d : Pipe", bestScore - 1)->getCString());
    }
     
    void GameScore::goMainInterface(cocos2d::Ref* pSender)
    {
         Director::getInstance()->replaceScene(TransitionFadeBL::create(1,
                  MainMenu::createScene()));
    }

    函数功能:http://www.cnblogs.com/geore/p/5800009.html 

    效果图:

  • 相关阅读:
    django学习第85天Django的Ajax
    django学习第84天Django常用字段和参数
    django学习第83天Django聚合查询.分组查询.FQ查询
    django学习第82天Django多表查询
    django学习第81天Django模板层2(单表查询.模块的导入和继承.静态文件配置)
    django学习第80天Django模板层1
    django学习第79天Django视图层
    Linux 内核文档翻译
    Linux设备模型——设备驱动模型和sysfs文件系统解读
    内核空间内存申请函数kmalloc kzalloc vmalloc的区别
  • 原文地址:https://www.cnblogs.com/geore/p/5800078.html
Copyright © 2011-2022 走看看