1
votes

Good day everyone.

I'm trying to draw the text "Pass Complete!" to screen with this code:

spriteBatch.DrawString(font, "PASS COMPLETE!", new Vector2(30, 130), Color.White);

Which does fire off the proper IF statement. However, how do I go about then removing that text from the screen? I'm really not sure at all where to go on from here and my instructor wants me to google the answer or find it in textbook. I have been all over my XNA textbook and I have found no outlet to removing that text.

Thanks for any and all help.

Update:

protected override void Draw(GameTime gameTime)

I have the IF statement included in here. Basically it checks collision with p_Receiver and if it the bool checks out, it draws the DrawString. Should I maybe be looking at this from a different angle?

Final:

I went ahead with the following as the answer and it's working better then before. :)

if (PassInfo == 3) {
(timer code)
(IF timer not "used up" then run the draw)

Working good for now.

I appreciate it.

2

2 Answers

1
votes

I'm doing this by function that add text with some parameters into generic list. and then i update and draw items from that list. in pseudo code:

function addText(text,position,duration)
    texts.add(new t(text,position,duration))
end function

function updateText()
    for each t as text in texts.findall(where t.active)
        t.duration -= 1
        if t.duration < 0 then t.active = false
    next
end function

function drawText()
    for each t as text in texts.findall(where t.active)
        //draw it
    next
end function

so by this you can add unlimited number of texts on different position and duration on screen.

0
votes

A lot of games redraw the entire window / screen each time through the draw cycle so there's a distinct chance that the solution to removing it is simply to stop drawing it.

i.e. have your if condition not draw the text when it is no longer required.

If, on the other hand, you've some more complex drawing logic that only draws portions of the window / screen that need updating then you'll need to include logic to redraw that part of the screen that contained the text once it is no longer needed.