I’m writing a simple 2d tilemap engine using C++ and SDL2.
Question:
I have a tile class that contains the data of a tile:
class cTile { private: // It basically says you should take a 32x32 part on sprite sheet // starting from (spriteSheetX, spriteSheetY), // and draw on screen at (positionX, positionY) int positionX; int positionY; int spriteSheetX; int spriteSheetY; }
and a cGraphics class that stores the sprite sheets and draw things on screen:
class cGraphics { public: void draw(int positionX, int positionY, int spriteSheetX, int spriteSheetY); }
Now that these two classes don’t know each other, but I want to call draw()
to draw the tiles. What are some good approaches to do that?
My thoughts:
- friend
- pass
cGraphics
tocTile
objects and create adrawTile()
incTile
that simply callsdraw()
incGraphics
- create a top class say
cGame
that knows both and calldraw()
from there (so basicallycGame
draws, plays sound, saves/loads, etc.)
Now that for games at this scale, probably all will suffice. I’m wondering what’s your thoughts? Note that cGraphics
is just one example. I can also have a cFile
that does save/load and serialization/de-serialization, a cSound
that plays some sound, etc.