Cocos2dx3.2 develop RPG Flighting (10) To add blood records to the role
I. Preface
The Role class actually has many attributes.
Protected:/* combat-related data */int m_id; // idRole * m_attackTarget; Role ** m_attackTargetPtr; // attack target Point m_desPoint; // ROLE_STAT en_stat; // Current Status FlightLayer * m_layer; // parent control int m_speed; // movement speed int m_initSpeed; int m_attackDistance; // attack distance int m_initAttackDistance; int m_hp; // life value int m_initHp; int m_atk; // attack force int m_initAtk; int m_defence; // defensive force int m_initDefence; ROLE_TYPE m_type; // role type: Monster Or Heroint m_atkHateValue; // hate bool m_isNaima attached to the attack; // is it a nurse std: string m_bulletImg; // The Bullet int m_bulletSpeed; // The Bullet speed int m_initBulletSpeed; double m_atkSpeed; // attack speed double m_initAtkSpeed;
I will not mention each attribute when it comes to the corresponding get/set method (such as attack power, defensive power, and blood volume). Please forgive me.
Ii. Text
There are many implementation methods for the blood size bar. Here I call the ControlSlider 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);}
Detects HP values in the update function and changes the blood size 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 m_hp value will change, naturally, and the amount of blood will change.
Here, the getHpSliderPos function is used to overwrite the quilt class and set the position of the blood size bar. It should be the size of the bone animation resources (maybe the Boss size is larger). Its nature is similar to the previous offset_x, offset_y is also used to adjust the position.