Originally Posted by
robert83
Hi,
thank you for the great tips, unfortunately this did not work
Code:
BackGround[i, j].ImageIndex = Images.Item[map.data[i,j+Offset]];
Code:
Images.Items[map.data[i,j+Offset]]
is returning a TAspyhreImage result and not Image index.
Actually you are providing Image index to this line by yourself using:
Code:
map.data[i,j+Offset]
So final code should probably look like this:
Code:
BackGround[i, j].Image := Images.Items[map.data[i,j+Offset]];
asuming that BackGround[i,j].Image is of TAsphyreImage type.
Originally Posted by
robert83
Also I was wondering if I could solve my sprite animation possible problems later like this ?
Code:
procedure TMain.LoadLevel;
var i,j : integer;
begin
for j := 0 to 14 do
begin
for i := 0 to 19 do
begin
BackGround[i,j] := TBackGround.Create(SpriteEngine);
BackGround[i,j].ImageName:= 'Empty.image';
BackGround[i,j].X:=i*32;
BackGround[i,j].Y:=j*32;
BackGround[i,j].Z:=1;
if BackGround[i,j].PatternCount > 1 then
begin
BackGround[i,j].AnimPos:=random(3);
BackGround[i,j].AnimCount:=3;
BackGround[i,j].AnimSpeed:=0.010;
BackGround[i,j].AnimLooped:=true;
BackGround[i,j].DoAnimate:=true;
end;
end;
end;
I belive it should work if PatternCount is automaticly calculated. Try setting a breakpoint inside a if clause to see whether code inside it do executes when needed. If not then probably PatternCount is always returning 1.
In your program you are using next line:
Code:
BackGround[i,j].AnimPos:=random(3);
This can break animation for continuos tiles like water since neighboring tiles are not synchronized (have different animation position). SO I strongly suggest that you get rid of it. Also you should note that generating random numbers is quite slow so if you call it often it can affect your program performance quite a bit.
Now I do understand that you would probbably like to have some random animations in case of some animated buildings so that they don't look just like clones of each other. But ass soon as you are dealing with some continuos tiles or contected tiles you need to synchronize their animation ogether.
Originally Posted by
robert83
I've found the code on the net, took out some parts I did not need....
Unfortunately the following did not work with dynamic arrays :
Code:
procedure TForm2.Button2Click(Sender: TObject);
var f:file;
begin
if OpenDialog1.Execute then
begin
assignFile(f,OpenDialog1.FileName);
reset(f,1);
blockread(f,map,sizeof(map)); // load map
closeFile(f);
// assign name again
Edit1.Text:=map.name;
end;
end;
The reason why this probably doesn't work is becouse you would need to first set the size of your arrays manualy by using:
Code:
SetLength(Map,Width,Height);
But I would rather suggest that you make your own map file type which would include all the needed information (width, height, number of layers, map name, etc); Making this would require a bit more code but if done properly would prevent you from having trouble when trying to load unsuported file.
If you want I can lend you some help in this but I need to know what kinda data structure are you trying to use in your map.
Also nice work on water texture.
Bookmarks