Previously, each graphic tile or sprite needed to be loaded into its own array. This limited working with large numbers of tiles or animations.
ARRAYDRAWTILE works like ARRAYDRAW for drawing the content of an array to the graphics screen except with three additional variables.
TILEWIDTH and TILEHEIGHT are used to specify the size of each tile or frame. TILEINDEX is used to specify which tile to draw.
Ozapell Basic can determine the index based on any image layout loaded. The image could contain a row of tiles, a vertical column of tiles or a two-dimensional page of tiles.
TILEINDEX begins in the upper, left corner as 0. The next tile to the right is 1, etc. until the next row. The leftmost tile of the next row will be the next index.
Example program assuming a bitmap image called tilepage.bmp is in the Ozapell Basic documents folder:
REM LOAD TILEPAGE.BMP INTO IMG ARRAY
IMG=0
FILENAME="TILEPAGE"
ARRAY=IMG
BITMAPLOAD
IMGWIDTH=WIDTH
REM GRAPHICS MODE
BACKCOLOR=COLORBLACK
MODE=1
SETMODE
REM DIVIDE IMAGE INTO 20X20 TILES AND SELECT FIRST TILE
TILEWIDTH=20
TILEHEIGHT=20
TILEINDEX=0
REM DRAW TILE AT 0,0 (UPPER LEFT CORNER)
X=0
Y=0
WIDTH=IMGWIDTH
ARRAYDRAWTILE
REM WAIT FOR KEY PRESS
REPEAT
INPUT
UNTIL RESULT
For working with sprite collision detection, ARRAYDRAWTILEOWNER assigns the value in the variable OWNER to each pixel drawn.