Load and Draw an Image in PlayBasic

How To Load and Draw an Image in PlayBasic

Declare a Variable

Before you load the image, you need to declare a variable to hold the image index. The image index acts as a handle by which you can manipulate the image.

ForceDeclaration

Declaration
    img
EndDeclaration

Load the Image

Now that you have a place to store the image index, load the image with LoadNewImage()

img = LoadNewImage("test_image.png")

Draw the Image

Draw the image with DrawImage. The code below draws the image at 32x, 32y. If you don't know what this means, take a look at this page.

DrawImage img, 32,32, 1

Draw The Frame

Finally, draw the frame with Sync

Sync

Complete Code

ForceDeclaration

Declaration
    img
EndDeclaration

img = LoadNewImage("test_image.png")
DrawImage img, 32,32, 1
Sync
WaitKey
End
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution 2.5 License.