Results 1 to 10 of 87

Thread: Space Shooter Game Editor

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #39
    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.
    Last edited by User137; 03-01-2013 at 10:23 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •