Blitz3D+ Command Reference

TileImage image[,x][,y][,frame]

Parameters

image - handle of the image to tile

x (optional) - horizontal offset of the tiling; 0 (default)

y (optional) - vertical offset of the tiling; 0 (default)

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

Description

Fills the whole drawing area with copies of an image, honouring its mask colour.

One call covers the current Viewport edge to edge, wrapping the image as many times as it takes. That makes wallpaper backgrounds trivial: a small seamless texture, a starfield, a brick pattern, a grid.

The real trick is the offset. x and y shift where the tiling starts and it wraps around, so incrementing them each frame scrolls the pattern forever with no seams and no bookkeeping. Two or three layers of starfield tiled at different speeds gives you parallax in a handful of lines; a value like x=-scroll and x=-scroll*2 on two layers is the whole effect.

Masked pixels stay transparent, so this is the one to use for an overlay layer - clouds, fog, a scanline pattern, a chain-link fence - drawn on top of something else. Use TileBlock when the tile is meant to be opaque; it is faster and is the right choice for a base background layer.

Tiling covers the viewport rather than the screen, so set a viewport first if you only want part of the display filled. The image's handle shifts the pattern too, which is worth knowing if you have centred it with MidHandle.

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

Example

; TileImage Example
; -----------------

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

star=LoadImage("media/star1.bmp")
player=LoadImage("media/player.bmp")

far_y#=0
near_y#=0

While Not KeyDown(1)

    Cls

    ; Two tiled layers scrolling at different speeds - instant parallax.
    ; TileImage repeats the image across the whole screen from an offset.
    far_y=far_y+0.5
    near_y=near_y+2
    TileImage star,0,far_y
    TileImage star,16,near_y

    ; The ship cruises over the starfield
    DrawImage player,MouseX(),MouseY()

    Text 0,0,"Move the mouse to fly   Esc: exit"
    Text 0,20,"TileImage star,0,"+Floor(near_y)+" - one small star fills the screen"

    Flip

Wend

End

Index