1

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.

AriesTiger
  • 69
  • 1
  • 8

2 Answers2

1

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.

Davor Mlinaric
  • 1,989
  • 1
  • 19
  • 26
0

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.

lzcd
  • 1,325
  • 6
  • 12
  • So should I then configure a block within the screen for screen updates and paint over that? It's simple enough as I have the background as Color.DarkGreen – AriesTiger Jul 08 '14 at 00:04
  • It's quite unusual for beginner level XNA apps to only being redrawing portions of the screen. It's far more likely that your app is redrawing the entire screen each draw cycle. Are you able to put a break point on your spriteBatch.DrawString(...) call to confirm this either way? If it is indeed being redrawn every time then the simple answer is that to remove it you just need to stop drawing it. – lzcd Jul 08 '14 at 00:08
  • You are correct it's being re-drawn over and over in the loop. So I should add in another check I'm guessing? Maybe a While statement? – AriesTiger Jul 08 '14 at 00:22
  • Shouldn't require a while statement.You just need to alter the if condition the surrounds the drawstring call so that it doesn't draw the string after you no longer need to display it. – lzcd Jul 08 '14 at 00:23
  • Ask yourself what the condition is to determine when the text should no longer be drawn (e.g. 2 seconds after it originally appeared on screen, when the objects are no longer touching etc). Then adjust and double check that your if condition is correctly determining such things. – lzcd Jul 08 '14 at 00:26
  • I understand better now. I appreciate it! – AriesTiger Jul 08 '14 at 00:27