Cocos2dx3.2 develop RPG Flighting (10) To add blood records to the role

Source: Internet
Author: User

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.

 

 



 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.