|
Screen are the first step to make a game, on the screen we can draw sprites and other type of elements to make our game,
this tutorial show how to load and draw a sprite on the screen. For this tutorial example we need a variable called Quit, and other for the
screen identifier called hScreen.
Declare Quit.b, hScreen.l
|
Then we can initialise DirectX and open our screen with OpenDXSreen() with size of 640x480 and 16 bits of colors:
If InitDXSprite() != 0
hScreen = OpenDXScreen(640, 480, 16, "VM Basic Sprite tutorial") != 0
If hScreen != 0
|
Load a bmp sprite as number 0 for normal sprite drawing:
LoadDXSprite(0, "vmmb.bmp", #VMB_SPRITE_NORMAL)
|
Now we add a repeat block of code until user want to quit our program, processing the event with ProcessEvent().
We also draw a sprite on the screen, checking that it is actived with IsScreenActive() to not draw the sprite
when the screen is minimized:
Repeat
ProcessEvent()
If KeyPushed(#VMB_KEY_ESCAPE) = #True
Quit = #True
EndIf
If IsScreenActive(hScreen) = #True
DrawDXSpriteFast(0, 100, 100)
FlipDXBuffers(#VMB_SCREEN_CLEAR, RGB(0, 0, 255))
EndIf
Until Quit = #True
|
Now we must to free the sprite loaded, close the screen and put the EndIf for DirectX init check and for open screen check and end our program:
FreeDXSprite(0)
CloseDXScreen()
EndIf
EndIf
EndProgram
|
Exercise:
Add commands necessary to move the sprite on horizontal direction when user push a specific key.
|
|