PDA

View Full Version : Problems with creating an Isometric Background Render



jdarling
22-04-2006, 05:14 PM
I've been working on a TISOBackgroundSprite implementation for unDelphiX and I've got a problem. Seems my background scrolls the opposite direction as EVERYTHING else in the unDelphiX Sprite Engine. Anyone have any ideas as to what I'm doing wrong? The unit is pasted below and I'd really appriciate it if anyone could take a look.

unit DXIso;

interface

uses
DXDraws, DXSprite, Windows, Classes;

type
TISOBackgroundSprite=class(TBackgroundSprite)
protected
procedure DoDraw; override;
function GetBoundsRect: TRect; override;
function TestCollision(Sprite: TSprite): boolean; override;
public
function WorldToIso(WoldPos : TPoint) : TPoint;
end;

implementation

uses
uDebugger,
SysUtils, Math;

{ TISOBackgroundSprite }

procedure TISOBackgroundSprite.DoDraw;
var
ChipHeight, ChipWidth, loopx, loopy,
OfsX, OfsY, TmpX, TmpY,
startx, starty, PatternIndex : Integer;
r : TRect;
begin
if Image=nil then
Exit;

if (MapWidth<=0) or (MapHeight<=0) then
Exit;

r := Image.PatternRects[0];
ChipWidth := r.Right-r.Left;
ChipHeight := r.Bottom-r.Top;

TmpX := Floor(WorldX);
TmpY := Floor(WorldY);

OfsX := (TmpX mod ChipWidth) + (ChipWidth div 2);
OfsY := TmpY mod (ChipHeight div 2);

startx := TmpX div ChipWidth;
starty := TmpY div (ChipHeight div 2);

DbgWriteLnFmt('StartX(%d), StartY(%d), WorldX(%f), WorldY(%f)', [startx, starty, worldx, worldy]);

for loopy := 0 to (Engine.Surface.Height div (ChipHeight div 2))+1 do
for loopx := 0 to (Engine.Surface.Width div (ChipWidth div 2))+1 do
begin
PatternIndex := Chips[loopx+startx, loopy+starty];
if PatternIndex > -1 then
Image.Draw( Engine.Surface,
loopx*ChipWidth+
((integer(odd(starty)) * integer(not(odd(loopy)))) or (integer(not(odd(starty))) * (loopy and 1)))
*(ChipWidth div 2)-OfsX,
loopy*(ChipHeight div 2)-(ChipHeight div 2)-OfsY,
PatternIndex
);
end;
end;

function TISOBackgroundSprite.GetBoundsRect: TRect;
begin
result := inherited GetBoundsRect;
end;

function TISOBackgroundSprite.TestCollision(Sprite: TSprite): boolean;
begin
result := inherited TestCollision(Sprite);
end;

function TISOBackgroundSprite.WorldToIso(WoldPos: TPoint): TPoint;
begin
end;

initialization
DisplayDebugWindow;

end.