Results 1 to 2 of 2

Thread: Problem with scrollbackground Z

  1. #1

    Problem with scrollbackground Z

    Hi I have big problem, when my character have moved under house or under tree on scrollbackground then my character to be on house or on tree it isn't good :roll: .

    I heve scrollbackground so I have map with trees, houses.....
    Maybe houses and trees need create not on scrollbackground.(chips/tiles)?

    How me do it, character moved in front tree then character to be on tree.
    character moved behind tree then character to be under tree.

    Thanks.

  2. #2

    Problem with scrollbackground Z

    I don't remember the correct term for this but what you need is something like a Z-Buffer. Basically you have to determine in what order you need to draw things in order to avoid the effect that you described.

    Here's how it can be done (in pseudo-code):

    [pascal]
    var
    DrawPlayer: Boolean;
    begin
    DrawPlayer := True;
    for J := 0 to MapHeight - 1 do
    begin
    for I := 0 to MapWidth - 1 do
    begin
    DrawTile(FloorLayer[I, J]);
    if (I = ScreenToWorld(PlayerX)) and (J = ScreenToWorld(PlayerY) + 1) and (ForeGroundLayer[I, J] > 0) then
    DrawPlayer(PlayerX, PlayerY);
    DrawTile(ForeGroundLayer[I, J]);
    DrawPlayer := False;
    else
    DrawTile(ForeGroundLayer);
    end;
    end;

    if DrawPlayer then
    DrawPlayer(PlayerX, PlayerY);
    [/pascal]

    This is completely untested but it could work
    Ask me about the xcess game development kit

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
  •