Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Drawing multiple sprites from same texture  (Read 3618 times)

0 Members and 1 Guest are viewing this topic.

TheMemo

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Drawing multiple sprites from same texture
« on: August 12, 2014, 11:58:29 pm »
Hi, I'm new to SFML, and I do quite like it. Just now I wrote a simple simulation of Conway's Game of Life. If you don't know what that is, it doesn't really matter, what matters is that you have to draw the same texture (a yellow square) to the screen multiple times at different positions (sometimes up to a few thousand times). Now, I'm wondering is there a significantly more efficient way of drawing the yellow squares (and nothing else, it's pretty rudimentary) than simply loading the texture (which is usually 3-10 pixels in height), linking a sprite to the texture, and then simply calling window.draw for every square for every frame. I don't think the code's gonna be really necessary here, it's 270 lines and quite awful.

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Drawing multiple sprites from same texture
« Reply #1 on: August 13, 2014, 12:09:59 am »
If you need it to be more efficient then you should use sf::VertexArray or make yourself an array containing sf::Vertex (shouldn't be difficult to calculate the positions of all vertices yourself), then draw that in one call.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Drawing multiple sprites from same texture
« Reply #2 on: August 13, 2014, 12:10:12 am »
What he said.  Note that one of the official tutorials covers this in detail: http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php