Jump to content

  • Log In with Google      Sign In   
  • Create Account

XNA icon cooldown clock effect


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 chosendeath   Members   -  Reputation: 110

Like
0Likes
Like

Posted 25 September 2012 - 07:29 PM

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.

Sponsor:

#2 ShadowValence   Members   -  Reputation: 380

Like
0Likes
Like

Posted 25 September 2012 - 08:47 PM

Given that the icons are normally all of similar sizes/dimensions, I'd guess that it's a semi-transparent animated sprite drawn over the original icon.

#3 chosendeath   Members   -  Reputation: 110

Like
0Likes
Like

Posted 26 September 2012 - 12:10 PM

I read a way to do it was the alpha mask thing, it seemed like the most efficient way to do it but I couldn't find a way to implement it in XNA.

#4 phil_t   Crossbones+   -  Reputation: 4094

Like
0Likes
Like

Posted 26 September 2012 - 12:53 PM

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.

#5 chosendeath   Members   -  Reputation: 110

Like
0Likes
Like

Posted 27 September 2012 - 09:45 AM

How would I do this?

#6 Tispe   Members   -  Reputation: 1046

Like
0Likes
Like

Posted 27 September 2012 - 09:58 AM

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, 27 September 2012 - 09:59 AM.


#7 chosendeath   Members   -  Reputation: 110

Like
0Likes
Like

Posted 30 September 2012 - 03:48 PM

That's not the alpha mask technique though, I want to do what phil said and use an alpha channel texture... but I don't how to use AlphaTestEffect properly with the spritebatch in XNA

#8 MrDaaark   Members   -  Reputation: 3555

Like
0Likes
Like

Posted 30 September 2012 - 07:32 PM

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.alphatesteffect_members.aspx

#9 chosendeath   Members   -  Reputation: 110

Like
0Likes
Like

Posted 02 October 2012 - 12:18 AM

Yes, but how do I use the AlphaTestEffect to actually draw something with the SpriteBatch? Sorry for my noobiness :(

#10 MrDaaark   Members   -  Reputation: 3555

Like
0Likes
Like

Posted 02 October 2012 - 12:21 AM

Set up an instance of AlphaTestEffect with the parameters set properly, and then pass it to SpriteBatch.Draw in one of the overloaded functions.

#11 chosendeath   Members   -  Reputation: 110

Like
0Likes
Like

Posted 02 October 2012 - 01:06 AM

But none of the overloads can take an AlphaTestEffect or any Effect it seems... the closest ones seem to be the ones with the SpriteEffects enum

#12 MrDaaark   Members   -  Reputation: 3555

Like
0Likes
Like

Posted 02 October 2012 - 06:22 AM

Oops.

Disregard that post. I haven't written XNA code in so long.

You use the blending options in SpriteBatch.Begin(). I believe it's BlendState.AlphaBlend or something similar.

#13 phil_t   Crossbones+   -  Reputation: 4094

Like
0Likes
Like

Posted 02 October 2012 - 10:59 AM

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 a little project here 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, 02 October 2012 - 11:02 AM.


#14 chosendeath   Members   -  Reputation: 110

Like
0Likes
Like

Posted 02 October 2012 - 10:06 PM

I have an alpha channel texture, but if its really required, how do I make a custom shader for it?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS