PDA

View Full Version : Problem with scrollbackground Z



Tadas
27-07-2004, 02:17 PM
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.

Harry Hunt
27-07-2004, 04:16 PM
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):


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);


This is completely untested but it could work :)