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?

Recommended Answers

All 2 Replies

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.

Got it to work. Thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.