Cocos2d-x game skill CD implementation

Source: Internet
Author: User
Tags dota

Monkey original, you are welcome to reprint, please note clearly! Thank you.

Address: http://blog.csdn.net/yanghuiliu/article/details/6917242

The most skill CD is used in the game.

One is a gray translucent transparent mask layer similar to the skill CD in Dota, Which is clockwise or counterclockwise.

The other is similar to building CD for plants in plants and botnets. Upper/lower Type mask layer.


In fact, cocos2d-x can easily achieve this effect.


Skill CD implementation in Dota:

CCProgressTimer* pt=CCProgressTimer::progressWithFile("cd.png");mPercentage=100;pt->setPercentage(mPercentage);


Cd.png is a translucent gray image. In this way, the percentage is set to 100. In this way, the CD layer is displayed and overwritten on the skill chart.


Turn the CD:

pt->setPercentage((100-mPercentage++));

OK. You can achieve this by setting the percentage value continuously.

As you can see, I reduced from 100 to 0, because the default value is 100 when the progress is full.


If you think this is unpleasant, you need to set it from 1 to 100. Alternatively, you only need to go to its source code. The file is ccprogresstimer. M. Just modify it.

Find this line of code float alpha = percentage _/100.f;


Add a piece of code below:

If (Alpha! = 0.f & Alpha! = 1.f)

{

Alpha =
1. F-alpha;

}

In this way, the truth is the same.


Skill CD implementation in Plants vs. botnets:






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.