<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                分數場景要用到TableView,這個之前也沒用過,主要參考網上的代碼。cocos2d-x的功能十分強大,以后還有好多東西要學啊! 分數場景類的.h文件中的內容 ~~~ class ScoreScene : public Layer, public TableViewDataSource, public TableViewDelegate { public: ScoreScene(); ~ScoreScene(); public: static Scene * createScene(); bool init(); CREATE_FUNC(ScoreScene); public: void tableCellTouched(TableView *table, TableViewCell * cell){}; TableViewCell * tableCellAtIndex(TableView * table, ssize_t index); Size tableCellSizeForIndex(TableView * table, ssize_t index); ssize_t numberOfCellsInTableView(TableView * table); void scrollViewDidScroll(ScrollView *){}; void scrollViewDidZoom(ScrollView *){}; //對返回鍵的響應 void onKeyReleased(EventKeyboard::KeyCode keyCode, Event * pEvent); private: Size size; ~~~ .cpp文件 ~~~ ScoreScene::ScoreScene() { } ScoreScene::~ScoreScene() { _eventDispatcher->removeEventListenersForTarget(this); } Scene * ScoreScene::createScene() { auto scene = Scene::create(); auto layer = ScoreScene::create(); scene->addChild(layer); return scene; } bool ScoreScene::init() { if (!Layer::init()) return false; //背景音樂 CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic(true); CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("sound/BackgroundMusic2.mp3", true); size = Director::getInstance()->getWinSize(); //添加背景圖片 auto background = Sprite::createWithSpriteFrameName("backgroundTollgateTwo.png"); background->setPosition(Point(size.width / 2, size.height / 2)); background->setAnchorPoint(Vec2(0.5, 0.5)); this->addChild(background); //創建tableView并設置一些參數 auto tableView = TableView::create(this, Size(size.width, size.height*0.8)); //設置滑動方向 tableView->setDirection(ScrollView::Direction::VERTICAL); //設置TableViewDelegate tableView->setDelegate(this); //index的大小是從上到下依次增大 tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN); //用當前的配置刷新cell tableView->reloadData(); this->addChild(tableView); //排名 auto dictionary = Dictionary::createWithContentsOfFile("fonts/AboutMe.xml"); auto rankNum = Label::createWithTTF( ((__String*)(dictionary->objectForKey("rankNum")))->getCString(), "fonts/DFPShaoNvW5-GB.ttf", 40); rankNum->setColor(Color3B(255, 0, 0)); rankNum->setPosition(Point(size.width*0.4, size.height*0.9)); this->addChild(rankNum); //得分 auto rankScore = Label::createWithTTF( ((__String*)(dictionary->objectForKey("rankScore")))->getCString(), "fonts/DFPShaoNvW5-GB.ttf", 40); rankScore->setPosition(Point(size.width*0.8, size.height*0.9)); rankScore->setColor(Color3B(255, 0, 0)); this->addChild(rankScore); //對返回鍵的響應 auto listener = EventListenerKeyboard::create(); listener->onKeyReleased = CC_CALLBACK_2(ScoreScene::onKeyReleased, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); return true; } //對返回鍵的響應 void ScoreScene::onKeyReleased(EventKeyboard::KeyCode keyCode, Event * pEvent) { if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE) { //背景音樂 CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic(true); CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("sound/game_start.mp3", true); //場景彈出 Director::getInstance()->popScene(); } } //用來設置每個cell的內容的 TableViewCell * ScoreScene::tableCellAtIndex(TableView * table, ssize_t index) { //設置每條記錄前邊的文本內容 auto index_text = __String::createWithFormat("%ld", index + 1); TableViewCell * cell = table->dequeueCell(); if (cell == NULL) { //創建一個cell cell = new TableViewCell(); cell->autorelease(); //創建顯示排名的文本信息 auto text = Label::createWithTTF(index_text->getCString(), "fonts/DFPShaoNvW5-GB.ttf", 24); text->setTag(1024); text->setColor(Color3B(255, 0, 0)); //文本信息在cell的中間 text->setPosition(Point(size.width*0.4, size.height*0.025)); cell->addChild(text); //顯示用戶得分的文本信息 auto index_score = __String::createWithFormat("%d", index); //根據index值獲得得分的文本,因為這個時候的score是int型,所以還需要轉化一下類型 int i_score = UserDefault::getInstance()->getIntegerForKey(index_score->getCString()); auto * str = __String::createWithFormat("%d", i_score); auto score = Label::createWithTTF( str->getCString(), "fonts/DFPShaoNvW5-GB.ttf", 24); score->setTag(2048); //設置坐標 score->setPosition(Point(size.width*0.8, size.height*0.025)); score->setColor(Color3B(255, 0, 0)); cell->addChild(score); } //這里獲得的cell是原來的cell,所以原來cell的文本信息等還是原來的,所以要做一些改變 else { //通過tag值獲得文本,并且改變 auto text = (Label *)cell->getChildByTag(1024); text->setString(index_text->getCString()); //改變分數 auto * score = (Label *)cell->getChildByTag(2048); auto * index_score = __String::createWithFormat("%d", index); int i_score = UserDefault::getInstance()->getIntegerForKey(index_score->getCString()); auto * str = __String::createWithFormat("%d", i_score); score->setString(str->getCString()); if (cell->getChildByTag(100) != NULL) { Sprite * sprite = (Sprite *)cell->getChildByTag(100); sprite->removeFromParentAndCleanup(true); } } if (index == 0 || index == 1 || index == 2) { Sprite * sprite; switch (index) { case 0: sprite = Sprite::createWithSpriteFrameName("gold.png"); break; case 1: sprite = Sprite::createWithSpriteFrameName("silvere.png"); break; case 2: sprite = Sprite::createWithSpriteFrameName("copper.png"); break; } sprite->setPosition(Point(size.width*0.15, size.height*0.025)); sprite->setTag(100); cell->addChild(sprite); } return cell; } //這個函數是用來設置每個cell的大小的 Size ScoreScene::tableCellSizeForIndex(TableView * table, ssize_t index) { return Size(size.width, size.height*0.05); } //這個函數是用來設置cell的個數的 ssize_t ScoreScene::numberOfCellsInTableView(TableView * table) { //個數是從XML文件中讀取到的,有多少條記錄,就設置多少個cell,如果剛開始沒有count這個字段,就返回0 int count = UserDefault::getInstance()->getIntegerForKey("count", 0); return count; } ~~~ 好了,這個游戲到這里就已經完成啦!再有的就是移植到其它平臺了。我是將這個游戲移植到了Android平臺。 代碼以及資源文件 [資源文件](http://download.csdn.net/detail/u011694809/9038951)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看