2
\$\begingroup\$

I want to code my own topdown 2D game with SFML+C++ that later shall have multiplayer functionality. Therefor I want to seperate the graphical and logical Parts of my game. All of my ingame Objects are thought to have Polygon-Hitboxes as their physical representation. What I now need is a graphical Representationn to draw them onto the Screen... I dont want to use tiles, because I want to have Support for rotated objects to and my Objects Are not evenly distributed so they wouldnt fit a grid.

My Question now is what would be the best way to graphically represent my Objects?

I thought of some ways but am not sure how you would ''normally'' do sth like that :)

Thought 1: As I only need two layers (For now(Floor and Things that you can collide with)) I thought my Floor could consist of tiles and then I draw my other Objects as sf::RectangleShapes or sf::Sprites onto it. (I would mix sprites and a more flexible approach here)

Thought 2: I only take sprites and include the objects that are ontop into each sprite that they should be drawn onto. (I think that it gets too messy and doesnt really ''solve'' my Problem)

Thought 3: I take each Object (Box, Part of the Floor(maybe each brick?)) and create an own textured sf::ConvexPolygon or sf::Rectangle for them. (Idk how big the impact on performance would be there)

PS: My approaches might seem a bit weird because I recently worked much with 3D-Software(eg Blender) and so I think of every Object to be a (2D) Mesh of Polygons that needs to be textured :)

I hope some of you can provide me some clarity on how to solve my Question :)

\$\endgroup\$
1
\$\begingroup\$

Your best bet is probably Thought 1: A simple tile map and sprites. Unless you're going full-blown OpenGL then doing things like texturing quads is a bit overkill since you're already using a graphics library.

Also, you don't need to make a polygon for your hitboxes; a simple rectangle will do in most cases.

\$\endgroup\$
  • \$\begingroup\$ Ok thank you :) I dont like the tilemaps approach because it is so limited. I have to overthink that :) but thank you very much for your opinion \$\endgroup\$ – sro5h Jul 23 '15 at 21:40
  • \$\begingroup\$ You don't necessarily need a strict tile map, but some form of "making a large landscape out of smaller pieces" engine for sure. It would really depend on the type of game you're making. \$\endgroup\$ – Sandalfoot Jul 23 '15 at 21:49
  • \$\begingroup\$ Its a shooter so no big rpg-like maps more like smaller maps. I would really like to be able to place the objects however i like. So like i got a box and i want it to be rotated by 20 degrees so that should be possible. Or walls that arent straight ... Btw whats the Problem with taking SF::rectangelshape and using it as a "container" for my textures. So my textures are little tiles that are repeated in that Rectangle, for the floor for example \$\endgroup\$ – sro5h Jul 23 '15 at 21:51
  • \$\begingroup\$ That's covered in your question; you have a floor layer and an object layer. For small maps you could either use a single large bitmap or a tile map, depending on your storage/flexibility requirements, for objects even with rotation you can still use a bounding box, but yeah at that point after you apply transformations it would be a general polygon - all I meant by not needing a polygon was that you probably shouldn't create a separate OpenGL-style primitive for it. Seems like you're on the right track though! \$\endgroup\$ – Sandalfoot Jul 23 '15 at 22:03
  • \$\begingroup\$ Yes i know i just tried to clarify what im looking for. Im gonna sleep about it and test performance with SF::rectangelshape then :). I already thought about a simple picture but it feels to cheap :D i want to do so that it is easy to edit and create New maps :) \$\endgroup\$ – sro5h Jul 23 '15 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.