Designing a Button

You can keep the code for your button in the same gui.cs code file you've been using up to this point (which is what the code on the included CD does), or you can put it in its own code file, which you would need to add to your project. Either way, add the class in Listing 5.9 to your code file.

Listing 5.9. The UiButton Class
 /// <summary> /// Will hold a 'button' that will be rendered via DX /// </summary> public class UiButton { private Sprite renderSprite = null; private Texture buttonTextureOff = null; private Texture buttonTextureOn = null; private Rectangle onSource; private Rectangle offSource; private Vector3 location; private bool isButtonOn = false; private Rectangle buttonRect; // The click event public event EventHandler ...

Get Beginning 3D Game Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.