tile scrolling in FLOATS no work!!!

Started by
5 comments, last by arwez 23 years, 7 months ago
I am using that gamedev article on tiling and added mapx and mapy global coordinates. Mapx and mapy are ints, when I increment them in decimals, the side where I am incrementing gets distorted. And I am aware that they are in ints, maybe if I change them to floats it will work, but I am not near my files at this time! I think it might have something to do with clipping or something. I am able to increment in whole tiles which is a little too fast. Here are some specs: tilesize: 40x40 resolution: 800x600 BPP: 16 bit Please help thx u!
Advertisement
anyone??
No, nobody (sorry I don''t know)
do you have a timer? why are you incrementing by integers? this doesn''t make sense. usually you incerement by a nice round number.

JoeMont001@aol.com 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
Ok first since mapx and mapy are coordinates they represent the location of a pixel (either on the map or on the screen, probably on the map b/c of the variables'' names).

You should not store pixel coordinates info in floats. Pixels are positive (unless you change the coordinate system) whole numbers. When you use floats it''s gonna just round off to the nearest integer.

Also you can''t do decimals with integers, it won''t work.

If this does not solve the problem, your problem seems to be with drawing the tile that has to be shown at the edge of the screen after the map is moved. Make sure the tile is loaded into memory and is clipped properly.



+AA_970+
ok, so how do I clip it? Can someone give me some code or something on the most easiest way to clip the tiles? I am really confused by some of the code out there.

THX!
Ok clipping tiles is really kinda easy once you understand it.

First you have a rectangle that defines your tile:

RECT rcRect;
rcRect.left = 0;
rcRect.top = 0;
rcRect.right = 40;
rcRect.bottom = 40;


Now you do something called culling, which checks if the tile is off the screen and stops it from being drawn:

if(x > 800) return FALSE;
if(y > 600) return FALSE;

// We use -40 b/c x & y are coordinates based on the tile's top
// left coordinates, therefore the tile's coordinates could be
// less than 0, but if they are less than -40 they are not
// visible.

if(x <= -40) return FALSE;
if(y <= -40) return FALSE;

Now for the clipping:

            // If part of the tile goes past the left edge of the screen// clip it by setting x to 0 (stop the tile from moving) and // make the left part of the rectangle equal to -x (remember// the x value is < 0 therefore it's negative, -(-x) = +x.if(x < 0){rcRect.left = -x;x=0;}// If part of the tile goes beyond the top of the screen...// This is the same as above only it's done on the y axis.if(y < 0){rcRect.top = -y;y=0;}// x & y represent where you want to place the tile based on// it's top left coordinates. To find out if the tile needs to// be clipped at the bottom or right sides of the screen we need// the bottom and right coordinates, we get this simply by // adding 40 to x and 40 to y. // Here we alter the right side of the rectangle. We do this by // 800 / x and taking the remainder, the modulus operator (%)// does this.if(x+40 > 800)rcRect.right = 800%x;// Again the method is repeated for the y axis.if(y+40 > 600)rcRect.bottom = 600%y;            





+AA_970+

Edited by - +AA_970+ on August 24, 2000 12:53:41 PM

Edited by - +AA_970+ on August 24, 2000 12:59:16 PM

This topic is closed to new replies.

Advertisement