Sign in to follow this  

XNA icon cooldown clock effect

Recommended Posts

In blizzard games, when a spell or item is on cooldown there is a clock effect over the icon. What would be the best way to do this in XNA? I tried using solutions from other posts but they didn't touch directly on XNA, and I couldn't figure out how to implement the solutions.

Share this post

Link to post
Share on other sites
In XNA you can use SpriteBatch with an AlphaTestEffect. Set the Alpha value to set the threshold above which something is drawn.

If you have a "disc" image with the alpha varying at different angles around the disc, then you could use this to display different "angle ranges" of the disc, so to speak.

Share this post

Link to post
Share on other sites
Take 5 vertices and make a square clock. Place vertices at 12, 3, 6 and 9 o'clock and one in the center.

The top and center vertex never moves.

The 3, 6 and 9 o'clock vertices you move in a circle using sin(tx+b) and cos(tx+b), where t is time, x is the scale and b is the phase/offset. Edited by Tispe

Share this post

Link to post
Share on other sites
You can supply an AlphaTestEffect in the SpriteBatch.Begin method. But you need to set it up with a special Projection matrix:

// Set up an AlphaTestEffect with a Projection that allows it to be used with SpriteBatch.
Matrix projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight, 0, 0, 1);
Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
alphaTestEffect = new AlphaTestEffect(GraphicsDevice);
alphaTestEffect.VertexColorEnabled = false;
alphaTestEffect.AlphaFunction = CompareFunction.Greater;
alphaTestEffect.ReferenceAlpha = 0;
alphaTestEffect.World = Matrix.Identity;
alphaTestEffect.View = Matrix.Identity;
alphaTestEffect.Projection = halfPixelOffset * projection;

I put [url=""]a little project here[/url] that shows how to use this to make a "clock" effect.

The only downside is that since you're using alpha to control the "angle" at which the "clock" is visible, you can't really use alpha blending. That's fine if you're ok with an opaque background.

Otherwise, you'd need to use a second "alpha texture" to control the angle; that would require writing a custom shader. Edited by phil_t

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this