Game Development Reference
In-Depth Information
using
Microsoft.Xna.Framework;
1
2
3
class
VisibilityTimer : GameObject
{
4
protected
GameObject target;
5
protected float
timeleft;
6
protected float
totaltime;
7
8
9
public
VisibilityTimer(GameObject target,
int
layer=0,
string
id = "")
:
base
(layer, id)
10
{
11
totaltime = 1;
12
timeleft = 0;
13
this
.target = target;
14
}
15
16
17
public override void
Update(GameTime gameTime)
{
18
−
=(
float
)gameTime.ElapsedGameTime.TotalSeconds;
timeleft
19
if
(timeleft <= 0)
20
target.Visible =
false
;
21
}
22
23
24
public override void
Reset()
{
25
base
.Reset();
26
timeleft = 0;
27
}
28
public void
StartVisible()
29
{
30
timeleft = totaltime;
31
target.Visible =
true
;
32
}
33
}
34
Listing 18.1
A timer class that controls the visibility of a game object
18.4.1 The Constructor
The constructor of the
GlitterField
class has several parameters. Here is the header of
the constructor:
public
GlitterField(Texture2D target,
int
density,
int
width,
int
height,
int
xoffset = 0,
int
layer = 0,
string
id = "")
:
base
(layer, id)
{
// initialize the glitter field object
}