First, preface
First of all, the role class actually has a lot of attributes.
protected:/* combat-related data */int m_id;//idrole* m_attacktarget; role** m_attacktargetptr;//attack Target Point m_despoint;//target location Role_stat en_stat;//Current state flightlayer* m_layer;//parent control int M_speed ;//move speed int m_initspeed;int m_attackdistance;//attack distance int m_initattackdistance;int m_hp;//health value int M_inithp;int m_atk;// Attack int M_initatk;int m_defence;//defensive force int m_initdefence; Role_type m_type;//Role Type: Monster Or heroint m_atkhatevalue;//attack comes with hate bool m_isnaima;//is not a nanny std::string m_bulletimg;// Bullet int m_bulletspeed;//bullet speed int m_initbulletspeed;double m_atkspeed;//attack speed double m_initatkspeed;
Each property has a corresponding Get/set method to use later (such as attack, defense, blood volume) may I do not mention, please forgive us.
Second, the text
The Blood bar is very basic, there are many ways to implement it, I'm calling Controlslider this control
void Role::inithpslider () {M_hpslider = Controlslider::create ("Bloodbg.png", "Blood.png", "sliderthumb.png"); m_ Hpslider->settouchenabled (false); M_hpslider->setmaximumvalue (M_INITHP); M_hpslider->setminimumvalue (0) ; M_hpslider->setvalue (M_HP); M_hpslider->setposition (Gethpsliderpos ()); This->addchild (M_hpSlider);} Point Role::gethpsliderpos () {return point (0,0);}
Detect HP values in the UPDATE function and change the blood bar
void role::update_hp () {if (M_hpslider) {m_hpslider->setvalue (M_HP); M_hpslider->setposition (GetHpSliderPos () );}}
When our injured function is triggered (attacked), the value of m_hp changes, and naturally, the blood bar changes as well.
The function of the gethpsliderpos here is to override the quilt class, and set the position of the blood bar, should be the size of the skeletal animation resources (perhaps the boss volume is a bit larger), the nature of the same as the previous offset_x,offset_y is used to adjust the position.
My csdn Address: http://blog.csdn.net/hezijian22
Email address: [Email protected]
If you have any questions or advice, please feel free to contact me.
cocos2dx3.2 development RPG "flighting" (10) for character plus Blood bar