Jump to content

How to create a circular cooldown effect?


Recommended Posts

I am struggling, the only resource I found is this

I have not dealt with the code yet, but concepts on how to deal with it. So the thought I came up with is to create a circle via PIXI.Graphics and make this a mask on another black transparent graphics object. The thing is, I wanted my Circle mask to look like a degrading pie chart overtime. I need to be it like this for some reason not like the one on the link. Basically, what I am asking is this, how can I make a circle, to fan left and to fan right (I don't know if I am using the right term)? I needed to draw a fanning effect so I can create a cooldown effect not just this, but some other cool stuff like a loading indicators something similar to Imgur, regardless the shape of my object of interest. 

Here is what I came up with:

This is fairly easy to do in Pixi.js or any other similar renderer libraries out there. But how can I make my circle to have a pie slice like this and it should grow overtime?

so I can make something like this (Not just specifically this by the way):


I don't like codes by the way. Just concept. I really can get my head wrap around this thing. I don't even know what its properly called (aside from calling it a circular cooldown effect) which made me even more frustrated.

I need help! Thanks!

Link to comment
Share on other sites

You could draw it by having the masked graphic be round and then build the mask by drawing line to start angle. Then moving it to edge off bounding box and then to end angle position and from that on back to origo. That way you would need only 4 basic lins instead of arcs. Not sure which one is faster though.

Here's an example:

var angle = -Math.PI*0.3 - Math.PI/2;
var angleStart= 0 - Math.PI/2;
var radius= 40;
test.beginFill(0xFF0000, 1);
test.moveTo(0, 0);
var x1= Math.cos(angleStart) * radius;
var y1= Math.sin(angleStart) * radius;
var x2= Math.cos(angle) * radius;
var y2= Math.sin(angle) * radius;
//Move to start point.
test.lineTo( x1 , y1);
//Move to left or right edge depending on which side the target is at.
test.lineTo( x2 < 0 ? -radius : radius, y1);
//Move to y-coordinate where end angle starts
test.lineTo( x2 < 0 ? -radius : radius, y2);
//Move to position where end angle starts
test.lineTo( x2, y2);
//Move back to center.
test.lineTo( 0, 0);

[Edit]: You could also calculate the distance to edge and use that as a radius multiplier for each angle and then just draw line to corner of bounding box. That way it would work also with rectangle graphics.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...