Fun Infused Games  |   Smooth Operator  |   Evil Scale  |   Starcraft Live  |   Wellplayed.net RSS Feed Available RSS 

  Home   |    Archive   |    Subscribe   |    Search   |    About

Posts prior to 8/2/2010 may be missing data. If you need one of those posts, please contact kriswd40@yahoo.com and I will try and recover/find it.

Pulsing Icons to Spruce Up your XNA Menus
Date 11/3/2009    Tags XNA, Game Development, Nasty    (3)

Static images are nice and all, but if you really want to draw the eye of a gamer to a specific command or object, try adding some movement or animation. In my game Nasty, there were some complaints on the Join screen that gamers weren't aware they had to hit A a second time to begin the game and some went as far as thinking the game was locked up. In order to remedy this (and generally make the Join screen look cooler), I decided to make the icons for the A button pulsate (grow bigger, grow smaller, repeat). This instantly draws your eye to them and makes it far more apparent that the game is waiting for you and not the other way around.

For this tutorial I am going to assume that you know how to setup / load / initialize a Texture2D object on your own (if not, it shouldn't be hard to look up). AButtonSmall will be that Texture2D object in this example.

In order to keep track of the size of the Texture2D object and whether it is growing or shrinking, we will create two new global variables.
private float AButtonScale = 1f; // 1f is the normal, non-scaled size.
private bool AButtonScaleUp = true; 
In the update loop that is ran while the menu / page displaying AButtonSmall, you will add the below logic for setting the current scale to draw the Texture2D object at.
// gameTime is a GameTime object passed into the update method or available globally.
float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

if (AButtonScale > 2f) 
{
    AButtonScaleUp = false;
    AButtonScale = 2f;
}
else if (AButtonScale < 1f)
{
    AButtonScaleUp = true;
    AButtonScale = 1f;
}

if (AButtonScaleUp)
{
    AButtonScale += elapsed * 2;
}
else
{
    AButtonScale -= elapsed * 2;
}
The first if/else statement ensures that the scale always stays within our acceptable range. I found 1 (original scale) and 2 worked best for my purposes but you may find something larger or smaller works better for you. If at any time you pass one of these bounds, the scale is set back to that bound and AButtonScaleUp is reversed (causing the Texture2D to pulsate in the opposite direction, as controlled by the second if/else statement).

Now all that is left is drawing to the screen. In your draw loop, at this code to draw the Texture2D.
Rectangle AButtonSmallSource = new Rectangle(0, 0, AButtonSmall.Width, AButtonSmall.Height);

int AButtonXOffset = Convert.ToInt32((AButtonScale * this.AButtonSmall.Width)/2f);
int AButtonYOffset = Convert.ToInt32((AButtonScale * this.AButtonSmall.Height)/2f);

spriteBatch.Draw(AButtonSmall, new Vector2(370 - AButtonXOffset, 600 - AButtonYOffset), 
    AButtonSmallSource, Color.White, 0.0f, Vector2.Zero, 
    this.AButtonScale, SpriteEffects.None, 0);
AButtonSmallSource is the source rectangle that you will use to draw your Texture2D. The AButtonXOffset and AButtonYOffset variables are used to make the Texture2D appear to grow in place from the center outward. If you just changed the scale without them, you would end up with a Texture2D that seemed<

Wellplayed.net
This article has been view 35 times.

Advertisement:

Comments

Matt Sams

Avatar

11/4/2009 8:05:58 AM

Nice demonstration, Kris. I think you're touching on something important here that pretty much everyone is missing. Polish. Generally I want to make sure that anything that requires human interaction has some kind of tactile feedback. Glows, pulsating, texture changes, etc. Audio feedback is definitely nice, too, if appropriate. The community probably needs more articles like this. :)t
Kris

Avatar

11/4/2009 12:36:01 PM

Thanks for the kind words Matt, I'm glad you liked this article. There are definately a lot of little things that can be done to polish a game that aren't always done (too many games get rushed out the door).

I haven't been doing too many tutorials here lately but I'm going to try and change that... one major aspect I'd like to cover more (as I did with this piece) is going to be things developers can do to add more polish to their game.t
Stegersaurus

Avatar

11/5/2009 10:10:33 AM

I would suggest using a sine wave instead of linear transitions in scale. It gives the pulsating a smoother look.

It's also a very quick change, where you just do something like this

double elapsed = gameTime.TotalGameTime.TotalSeconds;
AButtonScale = (float)((Math.Sin(elapsed*2)+1)/2 + 1);

Instead of your combination of if and else statements for direction. Though from my habits, I tend to also maintain a variable that sums up the elapsed time, and decrements it after it goes over Math.PI*2. But that's probably unnecessarry if you're using TotalGameTime instead of ElapsedGameTime.n


Add Comments

Current disabled. Check back soon!
top
top


top
Tags
ASP.net (17)  Annoyances (4)  Video Games (6)  Sage-Like Advice (12)  Domain Name (1)  Internet (5)  NFL (2)  Writing (1)  Visual Studio (1)  Hypership (12)  Site News (2)  Xbox (1)  C# (15)  Sage-Like Advise (1)  Education (1)  Tech Support (1)  MSSQL (1)  Absurd (1)  Abduction Action! (27)  Nasty (36)  Economy (1)  Cool (2)  Sports (11)  .Net (1)  Web Tools (2)  Abduction! (1)  Rant (40)  XBLIG (20)  Tutorial (2)  Nastier (1)  Books (1)  Realty (1)  Programming (3)  Weird (1)  Vista (1)  Development (14)  Design (3)  XNA (35)  Links (1)  Security (2)  JavaScript (7)  CSS (1)  Video (2)  Web Development (1)  Computing (1)  Abudction Action! (1)  Popularity (1)  Game Design (4)  Google (1)  AJAX (4)  Game Development (8)  
top

top
top


Twitter

    Follow me on Twitter



    Buy My Games:
    Abduction Action!
    Nasty

    I'm with Coco.