Smooth Scrolling
So have putted this Draw Tile Function in my little Tile Based Game:
int CWorld::DrawMap( int PosX, int PosY )
{
int tilex;
int tiley;
for(int y = 0; y < 40; y++)
{
for( int x = 0; x < 40; x++)
{
tilex = PosX+x*32-y*32; //x0,y0 is a reference point for the upperleft corner of tile (0,0)
tiley = PosY+y*16+x*16;
//use tilex and tiley to blit your tile
paint.DrawSurface( tilex , tiley, _RGB16BIT565( 255,0,255 ), lpDDSMapTiles[level->map[x][y].tile] );
}
}
return true;
}
How i can get there a smooth scrolling, the problem is that in this version every x,y of the map is drawing and when it`s big there is a fps like < 2,
thanx
Lutz Hören
[ Power Productions ]
psYchOtroW
EDIT : Irrelevant reply, bye bye ...
Edited by - morfe on December 26, 2000 8:38:26 PM
Edited by - morfe on December 26, 2000 8:38:26 PM
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
A few things:
-work on little optimizations to get higher frame rates.
-use frame based modeling. which is this:
-get a start time
-get an end time
-delta = end time - start time
-move objects by x+=delta*.01f (adjust accordingly for speed)
this way it''s not only smooth but runs the same speed on every computer.
JoeMont001@programmer.net www.polarisoft.n3.net
-work on little optimizations to get higher frame rates.
-use frame based modeling. which is this:
-get a start time
-get an end time
-delta = end time - start time
-move objects by x+=delta*.01f (adjust accordingly for speed)
this way it''s not only smooth but runs the same speed on every computer.
JoeMont001@programmer.net www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
The Problem with this drawing functions is that it draws every tile if it is on the screen or not, but let say that i have a map with x= 200, y=200 then when i draw all my tiles the fps is under 2. so i need a functions that only draws the tiles that are on the monitor at that moment
psYchOtroW
EDIT : Another irrelevant reply, bye bye ...
Edited by - morfe on December 26, 2000 8:39:07 PM
Edited by - morfe on December 26, 2000 8:39:07 PM
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
I wanna add my three cents worth... here's a little Turbo Pascal for pixel by pixel scrolling and i'll try do it in C++ to
Firstly we have our map and graphics (c++ at the end of the pascal)
Hope this helps....
E-mail me with the comments : Xsist10@hotmail.co
Edited by - Xsist on December 27, 2000 4:28:21 AM
Firstly we have our map and graphics (c++ at the end of the pascal)
map : Array[1..40,1..40] OF Byte; {40X40 map }pics : Array[1..256,1..10] OF Byte; {10 16X16 pics (remember 3D arrays cannot be block read)}{REM : 16X16=256}{Code Start}CONST No_Tiles_X = 14; No_Tiles_Y = 12;PROCEDURE LoadGraphics(FileName : String);VAR File1 : File; BEGIN Assign(File1,'FileName'); ReSet(File1,1); {The "1" tells TP that we are going to blockread} BlockRead(File1,Pics); END;PROCEDURE LoadMap(FileName : String);VAR File1 : File; BEGIN Assign(File1,'FileName'); ReSet(File1,1); {The "1" tells TP that we are going to blockread} BlockRead(File1,Map); END;PROCEDURE ShowMap(x,y,Speed : Integer);VAR a,b,c,d,xoff,yoff : Integer; {Xoff and Yoff for calculating} Loop1,Loop2 : Integer; {the offset between tiles} BEGIN FOR Loop1 := 1 TO (No_Tiles_X shl 4) DO BEGIN xoff := (x+Loop1) mod 16; c := (x+Loop1) shr 4; FOR Loop2 := 1 TO (No_Tiles_Y shl 4) DO BEGIN yoff := (y+Loop2) mod 16; d := (y+Loop2) shr 4; PutPixel(Loop1,Loop2,Pics[xoff+(yoff*16),Map[c,d]]); END; END; Delay(100-Speed); END;{Code End}Warning.... MOD and DIV commands each take about 23 cycles (multiplication takes +/- 7) so it will be fairly slow for big maps. However if you use a virtual screen it should be fine*/ Code Start /*Int Map[40][40]Int Pics[256][10]*/ I'm going to leave the graphics loading out because I don't /**/ know it yet.... (no-ones perfect) and there may be 1 or 2 /**/ mistakes in the code /*PROCEDURE ShowMap(x,ySpeed : Integer);VARa,b,c,d,xoff,yoff : Integer; {Xoff and Yoff for calculating}Loop1,Loop2 : Integer; {the offset between tiles}BEGINFOR Loop1 := 1 TO (No_Tiles_X shl 4) DObeginxoff := (x+Loop1) and 15;c := (x+Loop1) shr 4;FOR Loop2 := 1 TO (No_Tiles_Y shl 4) DOBEGINyoff := (y+Loop2) and 15;d := (y+Loop2) shr 4;PutPixel(Loop1,Loop2,Pics[xoff+(yoff shl 4),Map[c,d]]);END;END;END;*/ Code End /*
Hope this helps....
E-mail me with the comments : Xsist10@hotmail.co
Edited by - Xsist on December 27, 2000 4:28:21 AM
I burn cold
Multiplication takes one cycle? What planet are you from? It takes between 9 and 13 cycles.
And since mods and divs take so long, that''s why we use and instead of mod and shifts (shr, shl) instead of multiplication and division (of multiples of 2).
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..."
"When you are willing to do that which others are ashamed to do, therein lies an advantage."
And since mods and divs take so long, that''s why we use and instead of mod and shifts (shr, shl) instead of multiplication and division (of multiples of 2).
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..."
"When you are willing to do that which others are ashamed to do, therein lies an advantage."
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
I just realized i put my flat tile scrolling engine in....
use PsYchOtroW''s positioning until I modify it to work properely
but that is more or less what you need :
tilex = PosX+x*32-y*32;
tiley = PosY+y*16+x*16;
use PsYchOtroW''s positioning until I modify it to work properely
but that is more or less what you need :
tilex = PosX+x*32-y*32;
tiley = PosY+y*16+x*16;
I burn cold
sorry morfe, i just wanted to emphesise the bigger of burden of DIV and MOD to *
Also the code was old (i time when i hadn't discoverred SHR and SHL).. Thanks for pointing it out. By the way to any-one who doesn't know what SHL and SHR is it is SHifting the number Left or Right in binary form.
ie :
So :
12 SHL 1 = 12 * 2
12 SHL 2 = 12 * 4 (powers of 2)
therefore :
No_Tiles_X = 14
14 * 16 = 14 SHL 4 (sqrt(16))
and SHR is the same except moving the binary right
Edited by - Xsist on December 26, 2000 8:46:30 PM
Also the code was old (i time when i hadn't discoverred SHR and SHL).. Thanks for pointing it out. By the way to any-one who doesn't know what SHL and SHR is it is SHifting the number Left or Right in binary form.
ie :
32 16 8 4 2 112 in binary is 1 1 0 012 SHL 1 is 1 1 0 0 0 which equals 2412 SHL 2 is 1 1 0 0 0 0 which equals 48
So :
12 SHL 1 = 12 * 2
12 SHL 2 = 12 * 4 (powers of 2)
therefore :
No_Tiles_X = 14
14 * 16 = 14 SHL 4 (sqrt(16))
and SHR is the same except moving the binary right
Edited by - Xsist on December 26, 2000 8:46:30 PM
I burn cold
1. You can edit your own post (the little icon with the magnifying glass).
2. DIV 16 is SHR 4
3. Thus your procedure can go to this:
PROCEDURE ShowMap(x,ySpeed : Integer);
VAR
a,b,c,d,xoff,yoff : Integer; {Xoff and Yoff for calculating}
Loop1,Loop2 : Integer; {the offset between tiles}
BEGIN
FOR Loop1 := 1 TO (No_Tiles_X shl 4) DO
begin
xoff := (x+Loop1) and 15;
c := (x+Loop1) shr 4;
FOR Loop2 := 1 TO (No_Tiles_Y shl 4) DO
BEGIN
yoff := (y+Loop2) and 15;
d := (y+Loop2) shr 4;
PutPixel(Loop1,Loop2,Pics[xoff+(yoff shl 4),Map[c,d]]);
END;
END;
END;
But I still think it's overly complicated...
Edited by - morfe on December 26, 2000 7:55:28 PM
2. DIV 16 is SHR 4
3. Thus your procedure can go to this:
PROCEDURE ShowMap(x,ySpeed : Integer);
VAR
a,b,c,d,xoff,yoff : Integer; {Xoff and Yoff for calculating}
Loop1,Loop2 : Integer; {the offset between tiles}
BEGIN
FOR Loop1 := 1 TO (No_Tiles_X shl 4) DO
begin
xoff := (x+Loop1) and 15;
c := (x+Loop1) shr 4;
FOR Loop2 := 1 TO (No_Tiles_Y shl 4) DO
BEGIN
yoff := (y+Loop2) and 15;
d := (y+Loop2) shr 4;
PutPixel(Loop1,Loop2,Pics[xoff+(yoff shl 4),Map[c,d]]);
END;
END;
END;
But I still think it's overly complicated...
Edited by - morfe on December 26, 2000 7:55:28 PM
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement