2 Menus
Tim Young edited this page 2017-10-04 03:25:54 +02:00

Menus

It is not too difficult to make a nice-looking menu using sprites. The general concept is to make a bunch of sprites that are “buttons.” Each of these sprites should have an OnClick event. When the player clicks on that menu item, the code in your OnClick event will fire off.

You can also use a MouseHover (to pull up a tool-tip or something)

Many people will use the “MouseEnter” and “MouseLeave” to change the animation of a menu sprite to glow, pulse, or do something when the mouse is over the button. It is just very nice to have the button react to the mouse so the user knows which button they are over at any given time.

If all your menu sprites use the same animation scheme, it might look something like: Animation 0 is the menu item by itself. Animation 1 is it with the mouse over it (glowing, etc).

Then, all your buttons can share the same mouse-enter, and mouse-leave functions.

MenuSprite.MouseEnter += spriteMouseEnter;
MenuSprite.MouseLeave += spriteMouseLeave;

void spriteMouseEnter(Sprite MenuSprite, SpriteEventArgs e)
{
    MenuSprite.ChangeAnimation(1);
}

void spriteMouseLeave(Sprite MenuSprite, SpriteEventArgs e)
{
    MenuSprite.ChangeAnimation(0);
}

Because you may sometimes have some transparent areas surrounding a menu-button, you may also want to try out the MouseEnterTransparent, MouseLeaveTransparent, and MouseHoverTransparent functions. These work the same way, except that, instead of triggering when the mouse is over the sprite rectangle, it only triggers if it is over a non-transparent area of the sprite.

See also: Program Design: Menus