How can I make a templete or dynamical class for twice class?


#1

I got a 2 class for charater job.
so. I want to play Knight or HolyKnight.
When I init or refresh my hero, I don’t have a idea for class.
please help me What I do for init Charater?

class Knight : public CCSprite
{
int HP;
int ATK;
>
void setHP( int pHP);
};
>
class HolyKnight : public Knight
{
>
void useSkill();
};
>
class Layer : public CCLayer
{
…etc
>
void initCharater();
>
??? m_hero; // I don’t know What I select class.
};
>
>
void Layer::initCharater()
{
if ( I want HolyKnight )
{
m_hero = HolyKnight::create();
}
else
{
m_hero = Knight::create();
}
m_hero~~>setPosition);
addChild;
>
m_hero~~>setHP( 10 );
}


#2

You must set Knight, and for keeping a track of the type, i would recommend you to set tags over your sprites after initializing them.


#3

Thank you so much Barseghyan

Artavazd Barseghyan wrote:

You must set Knight, and for keeping a track of the type, i would recommend you to set tags over your sprites after initializing them.