Game Development Reference
In-Depth Information
using Microsoft.Xna.Framework;
1
2
3
class OnOffButton : SpriteGameObject
{
4
public OnOffButton( string imageAsset, int layer = 0, string id = "")
5
: base (imageAsset, layer, id, 0)
6
{
7
}
8
9
10
public override void HandleInput(InputHelper inputHelper)
{
11
if (inputHelper.MouseLeftButtonPressed() &&
12
BoundingBox.Contains(( int )inputHelper.MousePosition.X,
13
( int )inputHelper.MousePosition.Y))
14
sprite.SheetIndex = 1
sprite.SheetIndex;
15
}
16
17
18
public bool On
{
19
get
20
{
21
return sprite.SheetIndex == 1;
22
}
23
set
24
{
25
if ( value )
26
sprite.SheetIndex = 1;
27
else
28
sprite.SheetIndex = 0;
29
}
30
}
31
}
32
Listing 20.1
The class for representing an on/off button
the border width on the left and right side of the back sprite. Furthermore, we posi-
tion the slider slightly lower than the back sprite to account for the top border. The
complete constructor is then given as follows:
public Slider( string sliderback, string sliderfront, int layer = 0, string id = "")
: base (layer, id)
{
leftmargin = 5;
rightmargin = 7;
back = new SpriteGameObject(sliderback, 0);
Search WWH ::




Custom Search