Skip to main content
Post Closed as "Duplicate" by Anko, House
Improved grammar. Clarified what probably "feels wrong". More specific title. Helpful tag.
Source Link
Anko
  • 13.5k
  • 10
  • 56
  • 82

How to approach rendering in a 2D Sprite-based Should game objects draw themselves?

Let's assumeAssuming you have some classes like Player, Enemy, Map and Tile.

The first approach to structuring rendering code would be to give each a render() method and let the thingsit draw themself, e.g.itself:

void render(){
   player.draw();
   enemy.draw();
   // etc.
}

But considering the Model-View-Controller perspective, that doesn't feels rightwrong... the nextAnother idea would be to make a class Renderer class, but then I wonder how you give the Renderer information what to draw, so how to approach it.

Which one should I choose and why?

How to approach rendering in a 2D Sprite-based game?

Let's assume you have some classes like Player, Enemy, Map and Tile.

The first approach would be to let the things draw themself, e.g.:

void render(){
   player.draw();
   enemy.draw();
   // etc.
}

But that doesn't feels right... the next idea would be to make a class Renderer, but then I wonder how you give the Renderer information what to draw, so how to approach it?

Should game objects draw themselves?

Assuming you have classes like Player, Enemy, Map and Tile.

The first approach to structuring rendering code would be to give each a render() method and let it draw itself:

void render(){
   player.draw();
   enemy.draw();
   // etc.
}

But considering the Model-View-Controller perspective, that feels wrong... Another idea would be to make a Renderer class, but then I wonder how you give the Renderer information what to draw.

Which one should I choose and why?

Source Link

How to approach rendering in a 2D Sprite-based game?

Let's assume you have some classes like Player, Enemy, Map and Tile.

The first approach would be to let the things draw themself, e.g.:

void render(){
   player.draw();
   enemy.draw();
   // etc.
}

But that doesn't feels right... the next idea would be to make a class Renderer, but then I wonder how you give the Renderer information what to draw, so how to approach it?