• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Parallax scrolling

## Recommended Posts

OK, this isn''t really about parallax scrolling. I''ve got parallax scrolling working, and I know how that part of it works. I''m scrolling some stars. Each star has an X, Y, and Z coord. The X and Y are just int''s, and are relative to the world. The Z is a float and is used for several calculations like size of the star, color, junk like that. Here''s this code for rendering the stars: RECT FillRect; DDBLTFX fx; for (int index = 0; index < 1000; index++) { int color = 255 * stars[index].z; float z = stars[index].z; int x = stars[index].x; int y = stars[index].y; fx.dwFillColor = RGB(color, color, color); FillRect.left = (x - (tmpcamera->WorldX + 400)) * z; FillRect.top = (y - tmpcamera->WorldY); FillRect.right = FillRect.left + 3 * z; FillRect.bottom = FillRect.top + 3 * z; if (3 * z >= 1) GetBackBuffer->Blt(&FillRect,NULL,NULL,DDBLT_COLORFILL | DDBLT_WAIT, &fx); } It works great, but the problem is I want the camera''s X and Y to represent the center of the camera, not the upper left corner. How do I change the coordinate system?

##### Share on other sites
Oluseyi    2103
Add the offset to the center. If the center is at a y-position of 200, then the left edge is at -200 (because the center becomes your zero).
screen_y = world_y + 200;

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!