Created
April 27, 2018 20:48
-
-
Save 5HARK/d6ee20c846acc9ac6f8e6b1117f5cea8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MainScene.cpp | |
// NewCocosProject1 | |
// | |
// Created by jeunkim on 2017. 10. 24.. | |
// | |
// | |
#include "MainScene.h" | |
#include "HeroScene.h" | |
#include "ShopScene.h" | |
#include "GameScene.h" | |
#include "StageScene.h" | |
#include "Player.h" | |
MainScene :: MainScene() | |
{ | |
} | |
MainScene :: ~MainScene() | |
{ | |
} | |
Scene* MainScene :: createScene() | |
{ | |
auto scene = Scene :: create(); | |
auto layer = MainScene::create(); | |
scene->addChild(layer); | |
return scene; | |
} | |
bool MainScene :: init() | |
{ | |
if(!Layer::init()) | |
{ | |
return false; | |
} | |
auto rootNode = CSLoader::createNode("Main/MainScene.csb"); | |
this->addChild(rootNode,Z_ORDER::Level1); | |
auto topBar = rootNode->getChildByName<Layout*>("topbar"); | |
rootNode->reorderChild(topBar, Z_ORDER::Level3); | |
auto coin = topBar->getChildByName<Text*>("coin"); | |
char buf[1024] = {0,}; | |
string coinStr = myToString(Player::getInstance()->coin); | |
util_add_comma_to_num(coinStr.c_str(), buf, 1024); | |
coin->setString(myToString(buf)); | |
auto shopButton = rootNode->getChildByName<Button*>("shop"); | |
auto upgradeButton = rootNode->getChildByName<Button*>("upgrade"); | |
auto startButton = rootNode->getChildByName<Button*>("start"); | |
shopButton->addTouchEventListener([&](Ref *sender, Widget::TouchEventType type){ | |
if(type == Widget::TouchEventType::ENDED) | |
{ | |
auto scene = ShopScene::createScene(); | |
Director::getInstance()->replaceScene(scene); | |
} | |
}); | |
upgradeButton->addTouchEventListener([&](Ref *sender, Widget::TouchEventType type){ | |
//upgrade->setVisible(true); | |
if(type == Widget::TouchEventType::ENDED) | |
{ | |
auto scene = HeroScene::createScene(); | |
Director::getInstance()->replaceScene(scene); | |
} | |
//firebase::admob::rewarded_video::Show(getAdParent()); | |
}); | |
startButton->addTouchEventListener([&](Ref *sender, Widget::TouchEventType type){ | |
if(type == Widget::TouchEventType::ENDED) | |
{ | |
auto scene = StageScene::createScene(); | |
Director::getInstance()->replaceScene(scene); | |
} | |
}); | |
auto wait = Sprite::create("player/standing/st_1.png"); | |
wait->setPosition(960,540); | |
this->addChild(wait,Z_ORDER::Level2); | |
auto stAni = Animation::create(); | |
for(int i = 1; i <=9; i++) | |
{ | |
string filename = StringUtils::format("player/standing/st_%d.png",i); | |
stAni->addSpriteFrameWithFile(filename); | |
} | |
stAni->setDelayPerUnit(0.1f); | |
auto anim = Animate::create(stAni); | |
auto rev = anim->reverse(); | |
auto runSeq = Sequence :: create(anim,rev, nullptr); | |
auto stand = RepeatForever::create(runSeq); | |
wait->runAction(stand); | |
Player::getInstance()->updatePlayerCoin(); | |
this->scheduleUpdate(); | |
return true; | |
} | |
void MainScene::update(float dt) | |
{ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment