Advertisement

Smooth Scrolling

Started by December 25, 2000 04:36 PM
15 comments, last by PsYchOtroW 24 years ago
i think that you don`t understand me, i have this method:
  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;}  


but with this method i can scroll but i draw all my tiles from the level. So when i have a big World like 255x255 my fps is under 2... I need a draw function that only draws the tiles where i am.
psYchOtroW
EDIT : Yet another irrelevant reply, bye bye ...

Edited by - morfe on December 26, 2000 8:40:46 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
Advertisement
Thanks for the help morfe..... I think I need to get to bed earlier than usual. Its about 3:15AM here and I need my coffee.

Sorry about all the mistakes. I''m still getting used to the forum. How do you recommend I improve the code ? If i run it at 640X480 (full screen of tiles) it gets laggy

X-sist
I burn cold
There are tons of "smooth scrolling" threads in this FORUMN alone if you just click the "search" button. Not to mention the 2 ARTICLES on "scrolling maps", one by jim adams and other by martin estevao.

a) you need a "camera" to point somewhere on the screen.
b) you draw your map using this "camera" to find starting tile to draw at top left corner.
c) you dont draw the entire map..just the map tiles on the screen, referenced however you implement it from your "camera" point.
d) you add a value to the "camera''s" x or y value the same as direction you wish to scroll. this gives the scroll speed, and adjusts new "camera" position to calculate what is the first tile in your map to draw at upper left corner.

I cant overstate how many articles/THREADS there are about this topic and you really need to utilize it more!

aka John M.
Never give up. Never surrender!


Morfe: Did you see the X, Y variables ? then look at the paint.drawsurface function and then the surface choose, there you can see that this method will only draw the map from x 0 = to 20 and y = 0 to 30 but what if the map is bigger than 30 or 20 ? that`s my problem

Lutz Hören

[ Power Productions ]
psYchOtroW
Galaxy Quest,
the prob is that i am using a Diagonal Map method

Lutz Hören

[ Power Productions ]
psYchOtroW
Advertisement
Sorry, mea culpa Something like this, then?

  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 << 5 - y << 5;			tiley = PosY + y << 4 + x << 4;			if (tilex < 640) && (tilex > -32) && (tiley < 480) && (tiley > -16)			paint.DrawSurface( tilex , tiley, _RGB16BIT565( 255,0,255 ), lpDDSMapTiles[level->map[x][y].tile] );		}	}	return true;}  




"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

This topic is closed to new replies.

Advertisement