Is this about drawing visible map section of 2D grid? You don't need to add any variables to that for background class. It's just small tricks you do in the Draw (DrawLevel?) function.
1) You have worldX, worldY: single, floating point coords yeah? To get deltaX, deltaY, you can use function frac() for frac(worldX), drac(worldY). I don't know about your scaling, but on all maps i have done, 1.0 value in coords matches size of 1 tile. So if i draw player on 0.5, 0.5, it's in the middle of first tile.
2) Getting drawable area should be done from the rendering context, be it TForm, TPanel or TOpenGLContext. SX:=context.Width div TileWidth, SY:=context.Height div TileHeight.
3) When it comes to drawing...
Code:
iX:=floor(worldX);
iY:=floor(worldY);
for j:=iY-1 to iY+SY do
if (j>=0) and (j<SizeY) then
for i:=iX-1 to iX+SX do
if (i>=0) and (i<SizeX) then begin
DrawTile(i-iX+deltaX, j-iY+deltaY, @tile[i, j]);
end;
That's just from memory though, should work without much modifications.
Bookmarks