Jump to content
  • Advertisement

Archived

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

soundsystem

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

This topic is 5213 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:
				gogogo=false; 
			case SDL_KEYDOWN:
				if (SDLK_ESCAPE==event.key.keysym.sym)
					gogogo=false; 
			}
		}
		if (SDL_GetTicks()>=(oldticks+INTERVAL)) {
			oldticks=SDL_GetTicks(); 
			keys=SDL_GetKeyState(0); 
			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)
				sx=MAPWIDTH-SW;
			if (sy<0) sy=0; 
			if (sy>MAPHEIGHT-SH)
				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; 
		}

		FillScreen(); 
		DrawMap(sx, sy); 
		DrawHero(); 
		SDL_Flip(screen); 
		SDL_Delay(1); 
	}

Share this post


Link to post
Share on other sites
Advertisement
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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!