Tutorial 3 Part 2

If the text output of the previous tutorial was too basic for you, and you wish to have fancier text, take a look at this tutorial. We will be using pre-drawn sprites for our text.

Download this zip file (numbers.zip (6kb)) containing images of numbers and extract the files into a directory on your hard drive eg. "C:\TSS Dx-Creator\Tutorial3b\". Create a new project in this directory, putting a black 640 x 480 background image in bank 1.

At the moment the individual images of numbers aren't very useful to us. We need to make a sprite sheet from them. There is a very easy way to do this with the Sprite Sheet Wizard.

Add the images to the Sprite Sheet Wizard

From the "Tools" menu, select "Frame Creation" then "Frame Wizard" to run the Sprite Sheet Wizard. Click on the Plus icon and select the 10 images you downloaded earlier. Make sure that they are in the same order as they appear on your keyboard, in other words 1,2,3...8,9,0. The best way to do this is to add the images 1 to 9 and then add 0 afterwards. Select Next to continue.

Select automatic dimensions

On the next screen leave Automatic selected, and click Next.

Select Autosize

On the next screen leave Autosize selected, and click Next.

Check the preview image

On the next screen take a look at the preview image, and, all being well, select save. Save the sprite sheet into the same directory as the project. Click finish to end the Wizard.

Add the sprite sheet to bank 2 of your project. Now create a sequence in bank 3 using the sprite sheet you just created and these values: Sprite X = 30, Sprite Y = 30, Sprite Count = 10, X Count = 10.

Finally enter the following code into your project :

NOTE: If you do not wish to type the code below you may download or open this text file and simply copy and paste the code into your project.


//TUTORIAL 3 PART 2

//DEFINE VARIABLES

Global KEYPRESS

//DEFINE PROCEDURES
DefProc INIT_DISPLAY()
DefProc CREATE_SPRITES()
DefProc CHECKKEYS()

//---- START MAIN CODE ----

//CALL THE PROCEDURE TO CREATE THE SCREEN
INIT_DISPLAY()

//CALL THE PROCEDURE TO CREATE THE SPRITES
CREATE_SPRITES()

//START LOOP - THIS LOOP WILL REPEAT UNTIL ESC IS PRESSED
Repeat

    KEYPRESS = 0 //MAKE SURE THAT THERE IS NO VALUES STORED IN THIS VARIABLE

    Update Display

    KEYPRESS = ScanCode() //GET USER INPUT

    If KEYPRESS > 257 And KEYPRESS < 268 Then //IF A NUMBER KEY HAS BEEN PRESSED GOTO THE CHECK KEYS PROCEDURE

      CHECKKEYS()

    EndIf

Until KEYPRESS = 1 //PRESSING THE ESC KEY WILL QUIT

//THE INIT_DISPLAY PROCEDURE CREATES A SCREEN AND A PLANE
Procedure INIT_DISPLAY()

    Create Map 640,480,1,1 In Bank 50 //CREATE A MAP IN BANK 50
    Set Tile 0,0,1 Using Bank 50 //CREATE A TILE USING A BACKGROUND IMAGE IN BANK 1
    Create Plane 1 Using Bank 50 //CREATE PLANE 1 USING THE MAP IN BANK 50

EndProc

//THIS PROCEDURE WILL CREATE THE SPRITE
Procedure CREATE_SPRITES()

    Create Sprite 1,288,208 Using Bank 3 //CREATE SPRITE #1 AT 288,208 USING THE SEQUENCE IN BANK 3
    Sprites On //NOW TURN ON THE SPRITE SYSTEM
    Sprite Animate 1 Off

EndProc

//THIS PROCEDURE SETS THE SEQUENCE FRAME TO THE CORRECT NUMBER
Procedure CHECKKEYS()

    SetSequenceFrame(1,KEYPRESS-257) //CHANGE THE ANIMATION FRAME TO THE CORRECT NUMBER
    Sprite On 1 //ENABLE THE SPRITE

EndProc

EndProg


Run the project and press a number key. You will see the number appear in a nice fancy font. This is perhaps the easiest method of using pre-drawn sprites as text; storing them in a single sprite sheet and accessing them from a sequence using the SetSequenceFrame command. Otherwise, you will have many image banks and sequences for every character.

Fancy text in DXC

Previous Page