SFML community forums
Help => Graphics => Topic started by: wh1t3crayon on September 22, 2014, 08:07:13 pm
-
Correct me if I am wrong, but I can design an oddly shaped sprite myself by creating and storing a series of sf::vertex's, right? For instance, if I wanted to get the bounds of a sprite that's not a rectange shape, like a tetrimino that's not a square piece, I could set some sf::vertex's on the tetrimino's actual vertex's and call it a sprite, correct? The documentation is sort of weak on examples, so can somebody provide a more detailed explanation of how to use sf::vertex to create bounds for objects?
-
I think http://sfml-dev.org/tutorials/2.1/graphics-vertex-array.php covers that stuff pretty well.
-
A square sprite with transparency (PNG's work well) are also often useful for oddly shaped stuff :)
-
In case it's not clear, note that you can't define a custom shape directly with vertices, you'll have to combine several primitives to create more complex shapes. For a tetromino, you would combine 3, 4 or 5 quads for example.
-
In case it's not clear, note that you can't define a custom shape directly with vertices, you'll have to combine several primitives to create more complex shapes. For a tetromino, you would combine 3, 4 or 5 quads for example.
So, I couldn't define an irregular hexagon using a vertex array of 6 points? Are you saying that using several sf::FloatRect's would be the same thing?
-
You can do that with an sf::TrianglesFan and seven vertices (one for the center). The tutorial I linked even shows (most of) a regular polygon made out of one.
Fundamentally it's all triangles drawn between vertices you provide. A quad is just two triangles. A tetronimo happens to be made of squares so it's probably slightly simpler to do it with quads than triangles. That's all.
-
You can do that with an sf::TrianglesFan and seven vertices (one for the center). The tutorial I linked even shows (most of) a regular polygon made out of one.
Fundamentally it's all triangles drawn between vertices you provide. A quad is just two triangles. A tetronimo happens to be made of squares so it's probably slightly simpler to do it with quads than triangles. That's all.
How exactly is a trianglesfan used? The tutorial explains what it is but not really how to create one.
-
You create it by adding the points enumerated in the tutorial image... where exactly is the problem?
-
You create it by adding the points enumerated in the tutorial image... where exactly is the problem?
The problem is I'm trying to find a simple way to do collision detection for a simple game, but can't seem to find a way. I already have a topic on that, but I just posted this to find out if sf::vertex could get the job done. Apparently it would be just the same as using sf::rect, so I'll stick with that. Can you point me to a collisiom detection tutorial you'd recommend?
-
SFML's vertices are for rendering, not collision.
Write your own logic for collision detection and response. Which approach you use depends on your requirements regarding shape of the game objects and needed accuracy. Simple approaches entail rectangle or circle collision, more sophisticated ones are the Separating Axis Theorem (https://duckduckgo.com/?q=separating+axis+theorem+tutorial). For polygon intersection, you can also use existing libraries such as Boost.Geometry.