-
-
Save tks2shimizu/587ea98f879fb6fdb7e6 to your computer and use it in GitHub Desktop.
NyanRun (3)
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
// | |
// GameLayer.cpp | |
// nyanrun | |
// | |
// Created by Tomoaki Shimizu on 2013/02/05. | |
// Copyright TKS2 2013. All rights reserved. | |
// | |
#include "GameLayer.h" | |
#include "HelloWorldScene.h" | |
GameLayer::GameLayer() | |
: mBg1(NULL) | |
, mBg2(NULL) | |
, mBg3(NULL) | |
{ | |
} | |
GameLayer::~GameLayer() | |
{ | |
CC_SAFE_RELEASE(mBg1); | |
CC_SAFE_RELEASE(mBg2); | |
CC_SAFE_RELEASE(mBg3); | |
} | |
SEL_MenuHandler GameLayer::onResolveCCBCCMenuItemSelector(CCObject* pTarget, const char* pSelectorName) | |
{ | |
CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "tappedLeftFoot", GameLayer::tappedLeftButton); | |
CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "tappedRightFoot", GameLayer::tappedRightButton); | |
return NULL; | |
} | |
void GameLayer::tappedLeftButton(CCObject* pSender, CCControlEvent pCCControlEvent) | |
{ | |
tappedButton(); | |
} | |
void GameLayer::tappedRightButton(CCObject* pSender, CCControlEvent pCCControlEvent) | |
{ | |
tappedButton(); | |
} | |
void GameLayer::tappedButton() | |
{ | |
float moveTime = 1.0 / 3; | |
float moveDistanceForBG3 = (this->mBg3->getContentSize().width - CCDirector::sharedDirector()->getWinSize().width) / GOAL_COUNT; | |
CCMoveBy* move1 = CCMoveBy::create(moveTime, ccp(-moveDistanceForBG3 / 4, 0)); | |
this->mBg1->runAction(move1); | |
CCMoveBy* move2 = CCMoveBy::create(moveTime, ccp(-moveDistanceForBG3 / 2, 0)); | |
this->mBg2->runAction(move2); | |
CCMoveBy* move3 = CCMoveBy::create(moveTime, ccp(-moveDistanceForBG3, 0)); | |
this->mBg3->runAction(move3); | |
float moveDistanceForCat = CCDirector::sharedDirector()->getWinSize().width / 2 / GOAL_COUNT; | |
CCNode* cat = this->getChildByTag(1); | |
CCMoveBy* move = CCMoveBy::create(moveTime, ccp(moveDistanceForCat, 0)); | |
cat->runAction(move); | |
} | |
SEL_CCControlHandler GameLayer::onResolveCCBCCControlSelector(CCObject* pTarget, const char* pSelectorName) | |
{ | |
return NULL; | |
} | |
bool GameLayer::onAssignCCBMemberVariable(CCObject* pTarget, const char* pMemberVariableName, CCNode* pNode) | |
{ | |
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mBg1", CCSprite*, this->mBg1); | |
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mBg2", CCSprite*, this->mBg2); | |
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mBg3", CCSprite*, this->mBg3); | |
return false; | |
} |
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
// | |
// GameLayer.h | |
// nyanrun | |
// | |
// Created by Tomoaki Shimizu on 2013/02/05. | |
// Copyright TKS2 2013. All rights reserved. | |
// | |
#ifndef __GAME_LAYER__ | |
#define __GAME_LAYER__ | |
#include "cocos2d.h" | |
#include "cocos-ext.h" | |
USING_NS_CC; | |
USING_NS_CC_EXT; | |
#define GOAL_COUNT 100 | |
class GameLayer : public CCLayer | |
, public CCBSelectorResolver | |
, public CCBMemberVariableAssigner | |
{ | |
virtual SEL_MenuHandler onResolveCCBCCMenuItemSelector(CCObject* pTarget, const char* pSelectorName); | |
virtual SEL_CCControlHandler onResolveCCBCCControlSelector(CCObject* pTarget, const char* pSelectorName); | |
virtual bool onAssignCCBMemberVariable(CCObject* pTarget, const char* pMemberVariableName, CCNode* pNode); | |
void tappedLeftButton(CCObject* pSender, CCControlEvent pCCControlEvent); | |
void tappedRightButton(CCObject* pSender, CCControlEvent pCCControlEvent); | |
void tappedButton(); | |
public: | |
GameLayer(); | |
virtual ~GameLayer(); | |
CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(GameLayer, create); | |
protected: | |
CCSprite* mBg1; | |
CCSprite* mBg2; | |
CCSprite* mBg3; | |
}; | |
#endif /* __GAME_LAYER__ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment