forums

TNT Basic Forums > Programming Q&A
Draw Text Problem
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-25-2002 21:34

Posted by:
Tony Rose

Find more posts by Tony Rose

Is there a way I can draw the text to the canvas and have it stay there without updating it every frame?If I draw the text outside of my main loop,it wont continue to be displayed,and if I update it every frame it flickers. I would just make a sprite,but the text is for an ammo counter,and making that many sprites and importing them would be a major pain.

01-25-2002 23:44

Posted by:
Mark Tully

Find more posts by Mark Tully

Hi Tony,

You shouldn't get a flicker if you're redrawing the text everyframe, if the text is on the canvas everytime when you call 'draw frame' then it won't flicker. It will only flicker if it's there sometimes and not there othertimes.

There should be no problem at all using text as an ammo counter.

Simply:

pen colour black
paint rect x1,y1 to x2,y2 ' rect of ammo counter
draw text x1,y1+10,as string(gAmmoCount)

Once a frame and you'll be alright.

Mark

01-29-2002 19:08

Posted by:
Tony Rose

Find more posts by Tony Rose

Whats wrong?

I am drawing the text to canvas 0,the canvas all my sprites use fine,every frame and it still flickers. My code is as follows..

sprite 102,160,460,41'The frame around the text
draw text 161,470,as string(MachCounter)

There must be something wrong SOMEWHERE in all my lines of code and I cant find it :(

01-29-2002 23:34

Posted by:
Mark Tully

Find more posts by Mark Tully

Hmm..

If it flickers then it must be being copied to screen when it is there and also when it isn't there. How many calls to draw frame have you got, is it possible you're erasing the text and then calling draw frame by accident?

Try setting your framerate to 1, then it will be in slow motion, you might be able to see what's going on.

The score counter in Beans used to be text, and I don't remember that flickering.

See if you can write a simple example program that displays a counter increasing every frame. If that flickers then you've found a bug!

Good luck,

Mark

01-30-2002 19:19

Posted by:
Tony Rose

Find more posts by Tony Rose

Viewport?

I disabled all my procedures,1 by 1, until I found which one was causing the flicker. Upon disabling my viewport code the flicker stopped. Why?
Heres the code....

procedure viewport()
if scroll+viewport width (1) < 5120
scroll=scroll+0.5
end if

Set Viewport Offset 1,scroll,0

end proc

01-31-2002 10:30

Posted by:
Mark Tully

Find more posts by Mark Tully

Are you drawing the text over the view port? If so, you might want to make sure you draw the text after the viewport has scrolled.

Mark

01-31-2002 15:51

Posted by:
Tony Rose

Find more posts by Tony Rose

Take a look perhaps?

Yes,I am drawing my text after the viewport has scrolled. If anyone would like to take a look at my code,I can send it to you via email attachment. Its only 104k.

01-31-2002 17:38

Posted by:
ERaZer

Click Here to Email ERaZer   Find more posts by ERaZer

I could...

I could take a look at it and see if I can find the problem. My email is: theerazer@telia.com

01-31-2002 19:54

Posted by:
ERaZer

Find more posts by ERaZer

Hmm...

Tony, I tried to get your code to work but I couldn't. So I implemented a draw text thing in my code also and after some testing it seems like that viewports have a problem with anything drawn on Canvas 0...

01-31-2002 21:48

Posted by:
Mark Tully

Find more posts by Mark Tully

Problem?

Erazer,

A viewport is drawn into canvas 0, it will erase anything that is under it - is that what you mean? Please describe in detail what you are seeing and why you think it is wrong.

Tony,

Can you email me your code and I'll have a look at it. If there's a bug in TNT Basic we better move fast to get the fix in 1.02 which will be released very soon.

Thanks for your help!

Mark

02-01-2002 15:19

Posted by:
ERaZer

Find more posts by ERaZer

Hmm...

How can you then do it? Do you need to make a sprite of the text? Or how can you otherwise have a text thats drawn above everything and doesn't scroll? Is there something I've missed here or?

02-02-2002 15:03

Posted by:
Mark Tully

Find more posts by Mark Tully

Flickering Text

This is a copy of the email I just sent to Tony regarding this problem:


Hi Tony,

The flickering is caused by a quirk in the way TNT Basic handles viewports. Basically, when you scroll a viewport, the viewport is marked as needing copying into canvas 0 and drawing to screen. However, this is not done when the set viewport offset command is executed, but rather done in the draw frame statement.

So the procedure for TNT Basic's draw frame looks a bit like this:

DrawFrame()
if any viewports have scrolled
copy them into canvas 0
end if

draw sprites
update the screen
erase sprites
end proc

So your flickering text happens because:

1) you scroll the view port (which does nothing except mark the viewport as having scrolled)
2) you then draw the text into canvas 0
3) you then call draw frame (which copies the viewport into canvas 0 and erases your text).

Because you are scrolling by 0.5 pixel increments, the viewport will scroll by 1 pixel every two frames, hence one frame the viewport does not scroll and is not copied (that is the frame that your text gets drawn to screen) and the other the viewport is scrolled and is copied (that is the frame your text gets erased).

Now we could fix this by making the set viewport offset command copy the viewport into canvas 0 immediately, then you could draw over the top of the viewport in canvas 0 and your changes wouldn't be erased inside draw frame; but we don't want to do this. The reason being that a future version of TNT Basic will optimise viewports so that they never get drawn into canvas 0 at all, this will make it absolutely impossible to draw over viewports with text or other drawing commands, the only thing that will be able to go over viewports will be sprites. You will of course still be able to draw text into the canvas the viewport is viewing, but not over the viewport in canvas 0.

What I suggest is making your ammo read out into a sprite. Besides the problems with drawing over viewports with text, you also have the problem that if a sprite moves over the ammo counter it will be obscured (as sprites are drawn over the backdrop and the text is on the backdrop). The frame around the read out will not be obscured because that is a sprite, so it will look a bit odd.

Making sprites from text can be done easily at runtime by drawing all possible values of the ammo counter into a canvas and copying them into a sprite image with the 'get image' command.

If you really want to stick with text then I suggest either making room at the bottom of the screen for the counter (so you don't draw over the viewport) or not using viewports and instead use the 'copy canvas' command to copy the backdrop from canvas 1 to canvas 0 at the scroll offset. This is exactly the same as what viewports do except you will be able to draw over it.

Anyway, I hope this has explained the problem to you a bit. Best of luck with your game, it's looking good already!

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.