Hello,
SilverWarriror, I've changed my map layout to the one youv'e suggested :
Code:
TTileData=record
ImageIndex: integer; // Tile Number
AnimStart: integer; // Tile Animation Start Position
AnimSpeed: Single; // Tile Animation Speed
AnimCount: Integer; // Tile Animation Count
end;
TMapLine=array [0..19] of TTileData; // Stores one line of tile data
TMap=record
name:string[20]; // Name of the Map
map_length:integer; // Length of the Map
Lines: array of TMapLine; // stores the Entire map [0,0..19] , first value is 0 till map_length (vertical), second value is 0..19 (horizontal)
end;
I've also managed to get smooth scrolling working in one direction using your method (took me a while I know, had some brainfog issues, was sitting before this damn computer for many hours and nothing, couldn't even start...then yesterday it suddenly hit me.
This is the code that moves the map down ( I'll reverse my logic...and guess it'll work for up )
Code:
procedure TMain.TestExecute(Sender: TObject);
var x,y : integer;
new_line : boolean;
begin
if Offset < Map.map_length-14 then // -14 , Number of Tile Lines Drawn on Screen
begin
inc(Counter,1); // I'm using this to check if I've scrolled down one tile Height (32), if I did
if Counter = 32 then // then I'm increasing Offset by 1 and reseting Counter to 0, Offset is used to tell the new line of sprites which Line of TileData
begin // to read from the array
Inc(offset,1);
Counter:=0;
end;
for y:=0 to 15 do
begin
for x :=0 to 19 do
begin
BackGround[x,y].Y:=BackGround[x,y].Y-1;
if BackGround[x,y].Y = -32 then
begin
BackGround[x,y].Dead;
new_line := true;
end;
if new_line = true then
begin
BackGround[x,y]:= TBackGround.Create(SpriteEngine);
Edit9.Text:=inttostr(offset);
BackGround[x,y].ImageName:= Images.Item[map.Lines[offset+15,x].ImageIndex].Name;
if BackGround[x,y].PatternCount = 1 then
begin
BackGround[x,y].DoAnimate:=false;
end
else
begin
BackGround[x,y].AnimStart:=0;
BackGround[x,y].AnimCount:=map.Lines[offset+15,x].AnimCount;
BackGround[x,y].AnimSpeed:=map.Lines[offset+15,x].AnimSpeed;
BackGround[x,y].AnimPos:=(GlobalAnimCounter mod BackGround[x,y].AnimCount)+map.Lines[offset+15,x].AnimStart;
BackGround[x,y].DoAnimate:=true;
BackGround[x,y].AnimLooped:=true;
end;
BackGround[x,y].X:=x*32;
BackGround[x,y].Y:=480;
BackGround[x,y].Z:=1;
new_line:=false;
end;
end;
end;
end;
end;
Everything is nice with this, works like magic, but I have one problem... the animation is not in sync, I'm using GlobalAnimationCount as you've suggested (it works when I scroll trough the map line by line, but not when I do this smooth scrolling)
EDIT : actually the newly created TILE Lines are in sync , meaning each New line which has 15 Sprites , all of them 15 sprites are in sync, but everytime a new line is created it's not in sync with the previous line.
This is how GlobalAnimationCount is increased
Code:
if GlobalAnimCounter = 1000 then GlobalAnimCounter:=0;
inc(GlobalAnimCounter,1);
This above is defined on AsphyreDevice1.Render.
Any idea why my anim is out of sync when "smooth" scrolling down, but not out of sync when scrolling line by line. I'm doing the same thing on Drawlevel and there it works :
Code:
procedure TMain.CreateSprites;
var x,y : integer;
begin
// this procedure creates the starting sprites for one screen and fills them with Empty.image
for y := 0 to 15 do // vertically
begin
for x := 0 to 19 do // horizontally
begin
BackGround[x,y] := TBackGround.Create(SpriteEngine);
BackGround[x,y].ImageName:= 'Empty.image';
BackGround[x,y].X:=x*32;
BackGround[x,y].Y:=y*32;
BackGround[x,y].Z:=1;
end;
end;
end;
procedure TMain.DrawSprites;
var x,y: Integer;
begin
// this procedure changes the images for every sprite created at startup, creating the illusion of scrolling trough the map
// line-by-line
for y := 0 to 15 do // vertically
begin
for x := 0 to 19 do // horizontally
begin
BackGround[x,y].ImageName:= Images.Item[map.Lines[y+Offset,x].ImageIndex].Name;
if BackGround[x,y].PatternCount = 1 then
begin
BackGround[x,y].DoAnimate:=false;
end
else
begin
BackGround[x,y].AnimStart:=0;
BackGround[x,y].AnimCount:=map.Lines[y+Offset,x].AnimCount;
BackGround[x,y].AnimSpeed:=map.Lines[y+Offset,x].AnimSpeed;
BackGround[x,y].AnimPos:=(GlobalAnimCounter mod BackGround[x,y].AnimCount)+map.Lines[y+Offset,x].AnimStart;
BackGround[x,y].DoAnimate:=true;
BackGround[x,y].AnimLooped:=true;
end;
end;
end;
end;
EDIT : I was thinking that maybe I should use another counter , which would count the time between two created sprites ?
1 I create the initial sprites 16 lines 0..15 .
2 I start moving the sprites up (lines 0..15) and start the differential_timer
3 I destroy spriteline which is -32 , and add a new sprite line and reset differential timer to 0 ( here I'm not sure... I maybe do this ?
Code:
BackGround[x,y].AnimPos:=(GlobalAnimCounter-differential_timer mod BackGround[x,y].AnimCount)+map.Lines[offset+15,x].AnimStart;
)
and I keep repeating step 1,2,3 till I reach the end. This idea any good?
Greetings
Robert
Bookmarks