Board index » delphi » wrong layout on screen (bug?)

wrong layout on screen (bug?)

Hi,

I've got a problem I really don't understand. I want to draw
a map with 32x32 pixel tiles on the screen.
But if I use the code below I get a very strange result:
Only 6 rows are drawn, and in  the 6th row are 10 collums,
in the first 5(rows) 2. But if I switch the number of
cols and rows, everything works fine. It also works if
I set cols=3 and rows=3. But I get a error similar
to the first if i set cols=4 and rows=4 ???
I'm using the newest version of DelphiX and Delphi3
Professional.
Please help me !
I really don't understand my mistake.
Sorry for my english :-) !

procedure TForm1.FormCreate(Sender: TObject);
var i,rowcount,colcount: integer;
begin
 rows := 10;                      // number of rows
 cols := 2;                       // number of collums
 rowcount := 0;                   // counter for rows
 colcount := 0;                   // counter for collums
 for i := 1 to rows*cols do
  begin
   inc(colcount);
   map[i] := TMapTile.create(Spri{*word*249}gine.Engine);
   with map[i] do
    begin
     image := imagelist.Items[0];
     x := colcount*32;
     y := rowcount*32;
     height := image.height;
     width := image.width;
    end;
   if colcount = cols then
    begin
     colcount := 0;
     inc(rowcount);
    end;
  end;
end;

 

Re:wrong layout on screen (bug?)


Hi Jonas!

Have you tried something like this?
i := 1;
y := 0;
for rowcount := 0 to rows-1 do begin
  x := 0;
  for colcount := 0 to cols-1 do begin
    // here you should have the right values for x,y and i
    inc (x,32);
    inc (i);
  end;
  inc (y,32);
end;

Hope that works...
Jens

Jonas schrieb:

Quote
> Hi,

> I've got a problem I really don't understand. I want to draw
> a map with 32x32 pixel tiles on the screen.
> But if I use the code below I get a very strange result:
> Only 6 rows are drawn, and in  the 6th row are 10 collums,
> in the first 5(rows) 2. But if I switch the number of
> cols and rows, everything works fine. It also works if
> I set cols=3 and rows=3. But I get a error similar
> to the first if i set cols=4 and rows=4 ???
> I'm using the newest version of DelphiX and Delphi3
> Professional.
> Please help me !
> I really don't understand my mistake.
> Sorry for my english :-) !

> procedure TForm1.FormCreate(Sender: TObject);
> var i,rowcount,colcount: integer;
> begin
>  rows := 10;                      // number of rows
>  cols := 2;                       // number of collums
>  rowcount := 0;                   // counter for rows
>  colcount := 0;                   // counter for collums
>  for i := 1 to rows*cols do
>   begin
>    inc(colcount);
>    map[i] := TMapTile.create(Spri{*word*249}gine.Engine);
>    with map[i] do
>     begin
>      image := imagelist.Items[0];
>      x := colcount*32;
>      y := rowcount*32;
>      height := image.height;
>      width := image.width;
>     end;
>    if colcount = cols then
>     begin
>      colcount := 0;
>      inc(rowcount);
>     end;
>   end;
> end;

Other Threads