Global Vram

From Uzebox Wiki
Revision as of 22:40, 25 February 2010 by Paul (talk | contribs) (New page: The '''vram''' global variable is the array of tiles that will be drawn to the screen each frame. You can access it's elements directly or you can do so indirectly through [[Function_SetTi...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The vram global variable is the array of tiles that will be drawn to the screen each frame. You can access it's elements directly or you can do so indirectly through SetTile. To query it, you must access it directly. The exact size of the vram array is dependent on your Video Mode, but it's always VRAM_TILES_V * VRAM_TILES_H. For Video Mode 3, ram tiles will occupy the first RAM_TILES_COUNT elements of vram. Using SetTile will shelter you from these details.

Example:

#define TILE_WOOD 0
#define TILE_SAND 1
#define TILE_SHADOW 2
#define SLOW 3
#define FAST 6

u8 ballX, ballY; // Pixel precision
char ballVelX, ballVelY;
...
if (vram[(ballY>>3) * VRAM_TILES_H + (ballX>>3)] == TILE_WOOD)
    ballVelX = FAST;
else if (vram[(ballY>>3) * VRAM_TILES_H + (ballX>>3)] == TILE_SAND)
    ballVelY = SLOW;
...
vram[(ballY>>3) * VRAM_TILES_H + (ballX>>3)] = TILE_SHADOW;
          OR
SetTile(ballX>>3, (ballY>>3) * VRAM_TILES_H, TILE_SHADOW);