Setting up the Screen
Setting up the Pen
Drawing to the Screen
Draw Tracking
Canvases

Setting up the Screen
Before any graphics can be drawn using TNT Basic, the screen must set up. If you try to draw without setting up the screen first then TNT Basic will return an error saying that it needs to be in Graphics Mode first. To switch to Graphics Mode, use the following command...

Graphics Mode 640,480

This switches to Graphics Mode and sets up the screen so it has a width of 640 pixels and a height of 480.

Setting up the Pen
All drawing operations are performed using something called a pen. As the name suggests, the pen determines what the drawing operation will eventually look like. The pen has two different values associated with it, colour and transparency.

Colour
Colour controls the colour of the pen and hence the colour of the final drawing operation, it can be set by calling the command Set Pen Colour. This takes one parameter, a colour, which is the new colour for the pen.

Colours are built up from three components: red, green and blue. By mixing different amounts of these three colours any colour can be produced using the command Make Colour.

Make Colour (255,255,255)

This will produce white because maximum (255) red, green and blue produce white. Any colour can be produced in this way...

Make Colour (255,0,0) ' Red
Make Colour (0,255,0) ' Green
Make Colour (0,0,255) ' Blue
Make Colour (0,0,0) ' Black

In order to set the pen colour...

Set Pen Colour Make Colour (255,0,0)

This sets the pen colour to red. Any drawing operations from now on are performed in red.

Transparency
The transparency of the pen specifies how visible the drawing operations should be. It can be set using the command Set Pen Transparency.

Set Pen Transparency 100

This specifies that drawing operations should be completely visible (opaque). If you type in this...

Set Pen Transparency 50

... and then perform some drawing operations, you will notice that they are all slightly 'see-through'.

The transparency of a pen can be set to anything from 100 (opaque/completely visible) to 0 (transparent/invisible).

Drawing to the Screen
In order to draw to the screen any of the standard drawing operations can be used (e.g. Line, Fill Rect, Fill Oval etc.) e.g.

Graphics Mode 640,480
Set Pen Colour Make Colour (255,0,0)
Fill Rect 20,20 to 50,50
Wait Mouse Click

This piece of code will draw a red rectangle to the screen and then exit when the mouse button is pressed. However, if you run the program you will notice that nothing appears on the screen. This is because the new graphics you have drawn need to be copied to the screen. Change the program to be this...

Graphics Mode 640,480
Set Pen Colour Make Colour (255,0,0)
Fill Rect 20,20 to 50,50
Draw Frame
Wait Mouse Click

The Draw Frame command copies all the new graphics to the screen so you can now see the red rectangle that was drawn with the Fill Rect command.

Draw Tracking
When Draw Frame is called it copies all newly drawn graphics to the screen. In order for it to do this, it needs to have kept track of the areas of the screen that have changed and, when Draw Frame is called, copy these areas to the screen so the user can see them. This process can become quite slow, especially if you are drawing lots of things to the screen and TNT Basic has to keep track of a lot of areas. Fortunately though, this process can be accelerated. If you disable draw tracking using the command Draw Tracking...

Draw Tracking Off

...then TNT Basic no longer bothers to keep track of where your drawing operations have been performed. Now, when Draw Frame is called nothing is copied to the screen. In order to make TNT Basic copy graphics to the screen Inval Rect must be called. Inval Rect forces a specified area of the screen to be updated by the next call to Draw Frame. This area can be any size or can even be the entire screen.

Canvases
As you now know, drawing operations are all performed off screen where the user can't see them. They are then copied to the screen in one go so, to the user, they all appeared at the same time. When these drawing operations are performed off screen they are drawn into something called a 'canvas'. A canvas is exactly what it sounds - a thing that can be drawn on with whatever you like.

Ordinarily, drawing operations are performed into canvas 0, this canvas was created when Graphics Mode was enabled. Any drawing operations that are performed into canvas 0 can be copied to the screen during a Draw Frame call.

You are not limited to simply drawing just into canvas 0 though. More than one canvas can be opened and drawn in, images can also be copied from one canvas to another.

To create a canvas call the function Open Canvas...

Open Canvas 1,640,480

This opens canvas number 1 with the width 640 and the height 480. If canvas 1 already exists then it is closed and reopened at this size.

Note: Canvas 0 can never be opened or closed in this way, TNT Basic needs that canvas for the screen. It is opened and closed automatically when entering and leaving Graphics Mode and it is always the same size as the screen.

Drawing operations can be performed into canvas 1 exactly like they were into canvas 0 by setting it to the active canvas using the command Canvas.

Canvas 1

This sets the currently active canvas to canvas 1. That means that from now on any drawing operation (e.g. Line, Fill Rect) are drawn into canvas 1.

The contents of canvas 1 can be copied to the screen by using the command Copy Canvas to put them into canvas 0 and then calling Draw Frame to update the screen.

Copy Canvas 1 to 0

This copies the entire contents of Canvas 1 into Canvas 0 ready to be drawn to the screen.

Canvases use up a lot of memory so it is usually a good idea to only keep them open while you are actually using them. As soon as you have finished with it you can call the command Close Canvas.

Close Canvas 1

... to close the canvas. If the canvas being closed is currently targeted then the targeted canvas is reset to 0 again.

Table of contents