cocos2dx3.2 development RPG "flighting" (10) for character plus Blood bar

Source: Internet
Author: User

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

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.