Tutorial 2 Part 2

Now we will look at custom mouse pointers. Make sure you do Part 1 of this tutorial first!

  • Download this mouse pointer (pointer.bmp (1kb)) and copy the file into the same place as the files for the previous part of this tutorial. You may create your own mouse pointer if you wish. It just needs to be a BMP file and its size is unimportant (but don't make it too big or too small!)

  • In the same project that you created in the previous part of this tutorial, create a new image in the banks window and select the mouse pointer file. Create a new sequence and select the mouse pointer and enter the values : Sprite X = 16 (the width of the frame), Sprite Y = 15 (the height of the frame), Sprite Count = 1 (there is 1 frame in total), X Count = 1 (there is 1 frame on the only line in the sprite sheet)

  • Enter the code to create a new sprite in your CREATE_SPRITES() procedure (Create Sprite 2,100,100 Using Bank 5). Remember to turn the sprite on (Sprite On 2). You should also enter "Set Bitmap 4 Transparency To 0,0,255" into the INIT_DISPLAY() procedure so that the mouse pointer doesn't have a background.

  • Add a new procedure to your code called MOUSE_POINTER(). Add the DefProc command underneath the other DefProc commands and call the procedure before the main loop. In the procedure type in the Set Mouse Pointer command along with the sprite number (Set Mouse Pointer To Sprite 2). Add the command "Mouse Show" to turn the mouse on.

    Your code should look like this :

    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 2 Part 2

    //DEFINE VARIABLES

    Global KEYPRESS$

    //DEFINE PROCEDURES
    DefProc INIT_DISPLAY()
    DefProc CREATE_SPRITES()
    DefProc LOAD_MUSIC()
    DefProc MOUSE_POINTER()

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

    //CALL THE PROCEDURE TO CREATE THE SCREEN

    INIT_DISPLAY()

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

    //CALL THE PROCEDURE TO LOAD THE MUSIC
    LOAD_MUSIC()

    //CALL THE PROCEDURE TO CREATE THE MOUSE POINTER
    MOUSE_POINTER()

    SynthCommand(MIDI_Play) //PLAY THE MUSIC

    //START LOOP - THIS LOOP WILL REPEAT UNTIL A KEY IS PRESSED
    Repeat

      KEYPRESS$ = Inkey$()
      Update Display

    Until KEYPRESS$ > ""

    //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

      //CHANGE THE TRANSPARENCY OF THE SPRITES TO AN UNUSED OR BACKGROUND COLOUR
      Set Bitmap 2 Transparency To 0,0,255
      Set Bitmap 4 Transparency To 0,0,255

    EndProc

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

      Create Sprite 1,256,176 Using Bank 3 //CREATE SPRITE #1 AT 256,176 USING THE SEQUENCE IN BANK 3
      Create Sprite 2,100,100 Using Bank 5

      Sprite On 1 //ENABLE THE SPRITES
      Sprite On 2
      Sprites On //NOW TURN ON THE SPRITE SYSTEM
      Sprite Animate 1 Off //TURN OFF ANIMATION ON SPRITE 1

    EndProc

    //LOAD MIDI MUSIC
    Procedure LOAD_MUSIC()

      SynthLoad("music.mid") //LOAD THE MID FILE INTO MEMORY

    EndProc

    //CREATE MOUSE POINTER
    Procedure MOUSE_POINTER()

      Set Mouse Pointer To Sprite 2 //CHANGE THE DEFAULT POINTER TO THE SPRITE
      Mouse Show //TURN ON THE MOUSE (BY DEFAULT IT IS TURNED OFF)
    EndProc


    EndProg


  • If you run the project now, you will see that the mouse has a custom sprite pointer but at the moment you can only move it around the screen.

    The custom mouse pointer

    Previous Page  Next Page