0

Hey,

So I'm new to OpenGL but I've covered and played with the basics. I'm creating a 2D game and I want the view/camera/screen/whatever to follow the user controlled character (which is aimed to be centered at all times) creating a scrolling effect like that of, for example, Mario on the SNES.

I'm hoping there is a way for me to accomplish this by adding a few lines to my current code, where:

void processKeys(){

	if(keys[VK_LEFT])
	{
		Xcoord-=0.25;
	}

moves the user controlled character through translate

glTranslatef(Xcoord, Ycoord, 0.0);

If this can be done, how? If it can't, how should I attempt to get it working?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by BinaryAssassin
0

It won't be hard. First if you do the way you suggested to do it, i.e

if(RIGHT_KEY_PRESSED) moveScreen(World.RIGHT);

Then there will be a problem. The problem being that the screen will stutter. In fact try it out and see if its good enough, though.

What I would suggest it to do it one step up, and move the screen
relative to the player. So Find the middle of the screen, then calculate
how far the player is ways from the middle of the screen. Then if
the player passes the bounds you place on it, then move the screen
at the velocity of that of which the player is moving at. That way you
don't get any stutter, because of the different velocity the player and
the screen moves at.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.