Sign in to follow this  
bertong_uto

Design of simple game engines

Recommended Posts

Hello! I'm just starting out game development. I've always been confused on how to design my game, especially collision handling and rendering. For this topic let's assume I just use native Java (no OpenGL, etc).

 

For graphics, I just directly draw them on my off-screen buffer. I've heard that it is better to have a class that handles rendering. How does that work? Does that mean I should have a Renderer class, then just pass everything to be renderer onto it? I'm really confused on how to do this.

For the collision, what I do is:
1. Update position of all objects.

2. Check for collision (A `World` class handles all collision, is this fine?)

3. Resolve collision

I'm just stuck and confused. Mostly when I work I end up overthinking these things. I just want to clear them all up. Any help would be appreciated. smile.png

Share this post


Link to post
Share on other sites

There's a concept known as separation of concerns.  The reason people have a renderer class is so that nothing else in the engine needs to know how to actually draw things.  This means, among other things, that if you want to change how  you draw things (for example, using OpenGL, or making optimizations), you have exactly one place to look.

 

Typically, you have a list of things you want to draw.  Those things may store how they look in some fashion.  You pass those things off to the render, the renderer looks at how those things describe themselves (for example an image, or an enum of shapes or something), and knows how to draw that to the screen or back buffer.  For example (this is an extremely simplified example):

public class Renderer
{
  public void Render(List<GameObject> objects)
  {
    for(GameObject obj : objects)
    {
      Draw(obj.getImage());
    }
  }
  
  private void Draw(Image img)
  {
    // put whatever code you use to draw stuff here.
  }

}

Again, this is really simplified, and there's a gazillion ways you could make that better, but that's the general idea.

 

As far as collisions go, that's more or less the process, though there's plenty of space for optimization.  I don't know if I'd use a "world" class, since that sounds incredibly vague, but something has to know how to check for collisions between two objects.

 

EDIT: Because my Java sucks.

Edited by SeraphLance

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this