IMAGES

 

SaveImage

Stores the image to hard disk as BMP

Usage:

SaveImage image_variable, filename$ [, frame]

 

DrawImage

Renders an image to screen at given position. You can optionally specify image frame if you're using an animated image. In that case the image must have been loaded using the LoadAnimImage-function.

 

An image renders so that its upper left corner is positioned to the given coordinates. Also notice that images render 0-colour transparent. You can change that colour with the MaskImage-command. Or you can set the optional flag not to ignore mask colour in order to render image as it is.

 

Images render always to coordinates relative to screen, not to game world. However, you can change this behaviour by using the DrawToWorld-command.

Usage:

DrawImage image_variable, X, Y [, frame] [, transparency]

Example:

FrameLimit 40

'Load the map

themap=LoadImage("Media/map.bmp")

'Load an animated image

'Frame size is 30,25 \ start at the first \ 2 frames total

cow=LoadAnimImage("Media/animCow.bmp", 30, 25, 0, 2)

'Default Position

x=200:y=150

While Not EscapeKey()

    'Upadte controls

    If LeftKey() Then x=x-1

    If RightKey() Then x=x+1

    If UpKey() Then y=y-1

    If DownKey() Then y=y+1

    'Fraw the map

    DrawImage themap,0,0

    'Draw the cow

    DrawImage cow,x,y,cowframe

    'Animate through frames 0 and 1

    If TIMER()>cowtimer+100 Then 'animate every 100 millisecs

        cowframe=cowframe+1

        If cowframe>1 Then cowframe=0

        cowtimer=TIMER()

    EndIf

    DrawScreen

Wend

End

 

DrawGhostImage

Use the same way as DrawImage, but the transparency can be 0 to 100. 100 means fully opaque while zero non-visible. The value of 50 indicates semi-transparency. Any other value between interpolates. You can, for example, use this command for fading images in/out. But be warned! The translucency is performed by software-based algorithm, so using this command can seriously impact the game performance. Use carefully.

Usage:

DrawImage image_variable, X, Y [, frame] [, transparency]

 

DrawImageBox

Renders a portion of an image to screen.

Usage:

DrawImageBox image_variable, X, Y, startX, startY, width, height [, frame] [, transparency]

Example:

FrameLimit 40

imglifebar=LoadImage("Media/life.jpg")

life=100

While Not EscapeKey()

    'draw a constant portion

    DrawImageBox imglifebar,60,140,50,5,100,15

    'draw the changing portion

    DrawImageBox imglifebar,40,40,0,0,life*2,26

    'animate

    life=life-1

    If life<0 Then life=100

    DrawScreen

Wend

 

MaskImage

Sets the transparent colour of an image to something else than (0,0,0) which is the default. For example, if it's absolutely necessary to render the black parts also, you can mask it, say to Magenta.

Usage:

MaskImage image_variable, Red, Green, Blue

 

DefaultMask

If switched to ON, all loaded images are automatically masked to the given colour. This is handy if you load many images that need to be masked with the same key colour. You won't need to write MaskImages for all of them. When unneeded, just command DefaultMask OFF

Usage:
DefaultMask ON/OFF, Red, Green, Blue

 

ResizeImage

Does what the name says. Can also flip or mirror images by using negative dimensions.

Usage:

ResizeImage image_variable, newWidth, newHeight

 

RotateImage

Does what the name says. Angle is measured in degrees. After that the handle is moved to the center of the image. Meaning that the middle renders at the given coordinates – not the upper left corner.

Usage:

RotateImage image_variable, angle

 

PickImageColor, PickImageColor2

Picks a colour from the given image coordinates and sets it to current drawing colour. PickImageColor2 is for locked images (command Lock/Unlock) only.

Usage:

PickImageColor image_variable, X, Y

Example:

img=LoadImage("Media\palette.bmp")

ClsColor 255,255,255

Repeat

    DrawImage img,0,0,0,OFF   

    If MouseX()<ImageWidth(img) And MouseY()<ImageHeight(img)

        PickImageColor img,MouseX(),MouseY()       

        Box 100,100,50,30

    EndIf   

    DrawScreen

Until KeyHit(1)

 

HotSpot

Positions the image handle (the drawing position). Can also set the default position for all loading images.

Usage:

HotSpot image_variable/ON/OFF, X, Y

Example:

map=LoadImage("Media\map.bmp")

// Set the drawing point at 200,20

HotSpot map,200,20

// Notice that the image is introduced to be drawn to (0,0)

DrawImage map,0,0

// The image isn't really drawn at the top left corner

DrawScreen

WaitKey

 

DeleteImage

Frees an image from memory. After that the image can no longer be used, or the program will crash due to Memory Access Violation.

Usage:

DeleteImage image_variable

 

LoadImage

Loads an image to memory and returns it handle. Supported formats are: bmp, jpg, png and tga. Please notice that all images are destroyed if SCREEN-command is called and must be re-loaded. This is a DirectX-limit. Warning! You should NEVER load anything within a loop. There's a danger that you fill the memory.

Usage:

image_variable = LoadImage(filename$)

 

LoadAnimImage

The same as above, but enables loading of image-strips that contain more than one frames. See the DrawImage example.

Usage:

image_variable = LoadAnimImage(filename$, width, height, start, length)

Example:

FrameLimit 40

'Brackground white

ClsColor cbwhite

anim=LoadAnimImage("Media/note.bmp",32,32,0,8)

MaskImage anim,cbmagenta

While Not EscapeKey()

    'Draw the image

    DrawImage anim,184,134,f   

    'animate

    If k=0 Then

        f=f+1

        If f>7 Then f=0

    EndIf

    k=k+1

    If k>2 Then k=0 'change frame every 3. time

    DrawScreen

Wend

 

MakeImage

Creates an empty image (filled with black).

Usage:

image_variable = MakeImage(width, height)

 

CloneImage

Creates a copy from existing image.

Usage:

image_variable = CloneImage(source_image_variable)

 

ImageWidth

Tells the width of the given image, in pixels.

Usage:

w = ImageWidth(image_variable)

 

ImageHeight

Tells the height of the given image, in pixels.

Usage:

h = ImageHeight(image_variable)

 

ImagesOverlap

Returns True if two images drawn at given coordinates appear to be overlapping by invisible rectangles drawn over them based on their dimensions. This is a very fast way of detecting collision between two images, although it might be inaccurate, for example, with a ball and a square images.

Usage:

collision = ImagesOverlap(image1, x1, y1, image2, x2, y2)

Example:

'First make two images

img1= MakeImage(50,50)

img2= MakeImage(100,100)

DrawToImage img1

    Color cbred

    Circle 0,0,50

DrawToImage img2

    Color cbyellow

    Circle 0,0,100

DrawToScreen

 

'Initialize...

Color cbwhite

AddText "Arrows to move..."

x1=20

y1=20

x2=200

y2=150

'The game

Repeat

    'Update controls

    If LeftKey() Then x1=x1-1

    If RightKey() Then x1=x1+1

    If UpKey() Then y1=y1-1

    If DownKey() Then y1=y1+1

    'Draw both images

    DrawImage img1,x1,y1

    DrawImage img2,x2,y2   

    'Check for collisions

    Text 10,280,"Overlap: "+ImagesOverlap(img1,x1,y1,img2,x2,y2)

    Text 290,280,"Collision: "+ImagesCollide(img1,x1,y1,0,img2,x2,y2,0)   

    DrawScreen

Until EscapeKey()

 

ImagesCollide

Checks if two images overlap. The difference to ImagesOverlap is that this function performs pixel-perfect collision check providing max accuracy, but lesser performance.

Usage:

collision = ImagesCollide(image1, x1, y1, frame1, image2, x2, y2, frame2)

Example:

'First make two images

img1= MakeImage(50,50)

img2= MakeImage(100,100)

DrawToImage img1

    Color cbred

    Circle 0,0,50

DrawToImage img2

    Color cbyellow

    Circle 0,0,100

DrawToScreen

'Initialize...

Color cbwhite

AddText "Arrows to move..."

x1=20

y1=20

x2=200

y2=150

'The game

Repeat

    'Update controls

    If LeftKey() Then x1=x1-1

    If RightKey() Then x1=x1+1

    If UpKey() Then y1=y1-1

    If DownKey() Then y1=y1+1

    'Draw both images

    DrawImage img1,x1,y1

    DrawImage img2,x2,y2   

    'Check for collisions

    Text 10,280,"Overlap: "+ImagesOverlap(img1,x1,y1,img2,x2,y2)

    Text 290,280,"Collision: "+ImagesCollide(img1,x1,y1,0,img2,x2,y2,0)   

    DrawScreen

Until EscapeKey()