Don't follow the character. Have the character in a fixed position, and move the world behind the character instead.
If however you have your heart set on it, then write a map panning function. I assume you are using swing since you did not specify otherwise.
To do it, seperate your background drawing over to a texture, one that is sized about N^2 larger than the window resolution. Then draw a subrectangle of it over to the window canvas, and only flip once v-sync is ready. The key to making it center on the character is setting the subrectangle to the following coordinates.
X = CHARX - ((WINWIDTH - CHARWIDTH) / 2)
Y = CHARY - ((WINHEIGHT - CHARHEIGHT) / 2)
Make certain that Character is always within the following bounds of the texture, otherwise shift the map to compensate.
( ((WINWIDTH - CHARWIDTH) / 2) < x < TEXTWIDTH - ((WINWIDTH - CHARWIDTH) / 2) )
( ((WINHEIGHT - CHARHEIGHT) / 2) < y < TEXTHEIGHT - ((WINHEIGHT - CHARHEIGHT) / 2) )
Show differencesHistory of post edits
#1kd7tck
Posted 26 August 2012 - 03:43 PM
Don't follow the character. Have the character in a fixed position, and move the world behind the character instead.
If however you have your heart set on it, then write a map panning function. I assume you are using swing since you did not specify otherwise.
To do it, seperate your background drawing over to a texture, one that is sized about N^2 larger than the window resolution. Then draw a subrectangle of it over to the window canvas, and only flip once v-sync is ready. The key to making it center on the character is setting the subrectangle to the following coordinates.
X = CHARX - ((WINWIDTH - CHARWIDTH) / 2)
Y = CHARY - ((WINHEIGHT - CHARHEIGHT) / 2)
Make certain that Character is always within the following bounds of the texture, otherwise shift the map to compensate.
( ((WINWIDTH - CHARWIDTH) / 2) < x < TEXTWIDTH - ((WINWIDTH - CHARWIDTH) / 2) )
( ((WINHEIGHT - CHARHEIGHT) / 2) < y < TEXTWIDTH - ((WINHEIGHT - CHARHEIGHT) / 2) )
If however you have your heart set on it, then write a map panning function. I assume you are using swing since you did not specify otherwise.
To do it, seperate your background drawing over to a texture, one that is sized about N^2 larger than the window resolution. Then draw a subrectangle of it over to the window canvas, and only flip once v-sync is ready. The key to making it center on the character is setting the subrectangle to the following coordinates.
X = CHARX - ((WINWIDTH - CHARWIDTH) / 2)
Y = CHARY - ((WINHEIGHT - CHARHEIGHT) / 2)
Make certain that Character is always within the following bounds of the texture, otherwise shift the map to compensate.
( ((WINWIDTH - CHARWIDTH) / 2) < x < TEXTWIDTH - ((WINWIDTH - CHARWIDTH) / 2) )
( ((WINHEIGHT - CHARHEIGHT) / 2) < y < TEXTWIDTH - ((WINHEIGHT - CHARHEIGHT) / 2) )