Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


How to get the character to move


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 kennycastro007   Members   -  Reputation: 105

Like
0Likes
Like

Posted 09 August 2014 - 08:06 PM

I've been trying to make a 2d platformer, and I can't figure out how to make the player move when a key is pressed. Can anyone provide either a way to do this, or a link to a page that says how to? (I'm using modern opengl and I don't wan't to use an external library for this, as I am trying to get practice with OpenGL)



Sponsor:

#2 haegarr   Crossbones+   -  Reputation: 4425

Like
0Likes
Like

Posted 10 August 2014 - 03:49 AM

Character movement means to control the position an orientation of a game object. OpenGL is a graphics rendering API. So, movement of game objects has absolutely nothing to do with OpenGL. Instead, OpenGL can be used to render the current world state as is generated by other pieces of software.

 

Apart from that, your question is vague since you give very few details of how your world is organized at all. So here comes a coarse overview:

 

In principle you want to run the so-called game loop. At the beginning of a loop iteration you process player input. Such player input is e.g. "key W is pressed". Input processing means to translate such physical stuff into logical stuff. In the example this means "player avatar move forward". After input processing comes animation control (letting AI for NPCs aside). Animation control tries to perform the current command ("player avatar move forward"), but perhaps may not be able to do so because the avatar collides in the direction of interest, e.g. it has reached the top of the screen. If movement is possible, then animation control alters the current placement (i.e. position and orientation) and perhaps chooses another avatar picture or whatever. At the very last there comes rendering, using the given placement and other avatar state, and ... well ... renders it.



#3 BlueSpud   Members   -  Reputation: 426

Like
0Likes
Like

Posted 10 August 2014 - 08:10 AM

Well you would render the player as its own draw call and translate it by its position. Alternatively, you could translate the world instead if you wanted the player to stay fixed on the screen. For key input, you're going to need to use a library most likely. I would suggest SDL or glut. Glut is a lot less involved, but SDL is a lot more open, for instance you can control the main loop, whereas in glut you can't. Theres plenty of documentation on either of these. Good luck!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS