Jump to content
  • Advertisement


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


What's wrong with this tile scrolling code? Char moves faster than screen.

This topic is 5603 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The game sort of scrolls, but the characters is moving too fast, he goes off the camera, the camera follows but it''s like it''s too slow and lagging behind the character. SW and SH are the screen width and height (in tiles). This is how much tiles can be displayed at once on screen. sx and sy is the top/left coords of the screen display.
	while (gogogo) {
		while (SDL_PollEvent(&event)) {
			switch (event.type) {
			case SDL_QUIT:
			case SDL_KEYDOWN:
				if (SDLK_ESCAPE==event.key.keysym.sym)
		if (SDL_GetTicks()>=(oldticks+INTERVAL)) {
			if (keys[SDLK_w]) hero.y-=1; 
			if (keys[SDLK_s]) hero.y+=1; 
			if (keys[SDLK_a]) hero.x-=1; 
			if (keys[SDLK_d]) hero.x+=1; 

			sx = hero.x-(SW/2); 
			sy = hero.y-(SH/2); 

			// Screen can not go outside the bounds of the map

			if (sx<0) sx=0; 
			if (sx>MAPWIDTH-SW)
			if (sy<0) sy=0; 
			if (sy>MAPHEIGHT-SH)

			// Hero will always be within bounds of the screen 

			if (hero.x<0) hero.x=0; 
			if (hero.x>(sx+SW)) hero.x=sx+SW-1; 
			if (hero.y<0) hero.y=0; 
			if (hero.y>(sy+SH)) hero.y=sy+SH-1; 

		DrawMap(sx, sy); 

Share this post

Link to post
Share on other sites
I don't think you are remembering to use the hero's width/height when figuring out the top corner coordinates. (Unless the hero is a pixel O_o)

[edited by - MetaCipher on June 5, 2004 12:05:56 AM]

Share this post

Link to post
Share on other sites
Try Using

sx = (hero.x*TILESIZE/2)-(SW/2);
sy = (hero.y*TILESIZE/2)-(SH/2);

You have to use the hero''s central point.
(TILESIZE/2 assuming its a square)

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!