Blitz3D+ Command Reference

DrawBlock image,x,y[,frame]

Parameters

image - handle of the image to draw

x - x position to draw at

y - y position to draw at

frame (optional) - frame of an animated image to draw; 0 (default)

Description

Draws an image solid, ignoring its mask colour.

It is DrawImage with transparency switched off. Every pixel of the image is written, including the ones that match the mask colour set by MaskImage (black by default), so the image lands as an opaque rectangle.

That makes it the right choice for anything that is meant to cover what is underneath: backgrounds, full-screen title art, sky layers, a solid tile you are blitting into a level surface, or the moment you want to stamp a sprite complete with its black background. It is also the faster of the two, because nothing has to be tested pixel by pixel.

The x,y is measured from the image's handle, which is the top left corner unless MidHandle, HandleImage or AutoMidHandle has moved it, and it is relative to the current Origin. Drawing partly or wholly off the edge of the buffer is fine - the image is clipped.

If your sprite looks like it is sitting on a black card, you have used DrawBlock where you meant DrawImage.

See also: DrawImage, DrawBlockRect, TileBlock, MaskImage, LoadImage.

Example

; DrawBlock Example
; -----------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; Ship sprite - the pixels around the ship are the mask colour (black)
player=LoadImage("media/player.bmp")

While Not KeyDown(1)

    Cls

    ; A chequered backdrop so transparency (or the lack of it) is obvious
    Color 40,40,90
    For y=0 To 460 Step 20
        For x=0 To 620 Step 20
            If ((x+y)/20) Mod 2=0 Then Rect x,y,20,20,True
        Next
    Next

    ; DrawImage honours the mask; DrawBlock draws every pixel, mask included
    DrawImage player,MouseX()-60,MouseY()
    DrawBlock player,MouseX()+28,MouseY()

    Text MouseX()-44,MouseY()+44,"DrawImage",True
    Text MouseX()+44,MouseY()+44,"DrawBlock",True

    Text 0,0,"Move the mouse   Esc: exit"
    Text 0,20,"DrawBlock ignores the mask - the black box around the ship is drawn too"

    Flip

Wend

End

Index