Created
June 25, 2014 12:06
-
-
Save sdkfz181tiger/10fda877757e96aa2ab3 to your computer and use it in GitHub Desktop.
CountDownSprite(Cocos2dx_ver3.0)
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
// | |
// CountDownSprite.cpp | |
// Oyadius3 | |
// | |
// Created by Shimeji Ozaki on 2014-06-22. | |
// | |
// | |
#include "CountDownSprite.h" | |
CountDownSprite::CountDownSprite(float posX, float posY, | |
float vX, float vY, int countNum):BaseSprite(posX, posY, vX, vY){ | |
this->countNum = countNum; | |
} | |
CountDownSprite::~CountDownSprite(){ | |
} | |
CountDownSprite* CountDownSprite::create(float posX, float posY, | |
float vX, float vY, int countNum){ | |
CountDownSprite* sprite = new CountDownSprite(posX, posY, vX, vY, countNum); | |
if(sprite && sprite->initWithSpriteFrameName("space_25.png")){ | |
sprite->autorelease(); | |
sprite->setPosition(Point(posX, posY)); | |
sprite->makeStage(countNum); | |
return sprite; | |
} | |
CC_SAFE_DELETE(sprite); | |
return NULL; | |
} | |
void CountDownSprite::update(float dt){ | |
if(getMoveEnabled()){ | |
setPosX(posX + vX * dt); | |
setPosY(posY + vY * dt); | |
this->setPosition(Point(posX, posY)); | |
} | |
} | |
// born | |
void CountDownSprite::born(){ | |
this->setAliveEnabled(true); | |
} | |
// die | |
void CountDownSprite::die(){ | |
this->setAliveEnabled(false); | |
} | |
// intersect | |
bool CountDownSprite::intersect(const Rect& targetRect){ | |
return this->boundingBox().intersectsRect(targetRect); | |
} | |
// makeStage | |
void CountDownSprite::makeStage(int countNum){ | |
char cn[5]; | |
sprintf(cn, "%01d", countNum); | |
float centerY = this->boundingBox().size.width * 0.5f; | |
myLabel = CCLabelBMFont::create(cn, "MisakiGothic.fnt"); | |
myLabel->setColor(Color3B(255, 255, 255)); | |
myLabel->setPosition(Point(centerY, this->boundingBox().size.height/2)); | |
this->addChild(myLabel); | |
} | |
// updateTime | |
void CountDownSprite::updateView(int countNum){ | |
if(this->countNum != countNum){ | |
this->countNum = countNum; | |
char cn[5]; | |
sprintf(cn, "%01d", countNum); | |
myLabel->setString(cn); | |
// animation | |
ScaleTo* sToA = ScaleTo::create(0.2f, 3.0f); | |
ScaleTo* sToB = ScaleTo::create(0.2f, 1.0f); | |
this->runAction(Sequence::create(sToA, sToB, NULL)); | |
} | |
} |
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
// | |
// CountDownSprite.h | |
// Oyadius3 | |
// | |
// Created by Shimeji Ozaki on 2014-06-22. | |
// | |
// | |
#ifndef __Oyadius3__CountDownSprite__ | |
#define __Oyadius3__CountDownSprite__ | |
#include "BaseSprite.h" | |
#include "UtilMath.h" | |
USING_NS_CC; | |
class CountDownSprite:public BaseSprite{ | |
private: | |
LabelBMFont* myLabel; | |
int countNum; | |
public: | |
CountDownSprite(){}; | |
CountDownSprite(float posX, float posY, float vX, float vY, int countNum); | |
~CountDownSprite(); | |
static CountDownSprite* create(float posX, float posY, | |
float vX, float vY, int countNum); | |
// update | |
virtual void update(float dt); | |
// born | |
virtual void born(); | |
// die | |
virtual void die(); | |
// intersect | |
virtual bool intersect(const Rect& targetRect); | |
// makeStage | |
virtual void makeStage(int countNum); | |
// updateView | |
virtual void updateView(int countNum); | |
}; | |
#endif /* defined(__Oyadius3__CountDownSprite__) */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment