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

Author Topic: A way to cobble sprites?  (Read 2753 times)

0 Members and 1 Guest are viewing this topic.

Austin J

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
A way to cobble sprites?
« on: April 08, 2014, 07:00:11 pm »
  I have a map editor, which uses a sprite for each tile. Obviously since it's a map editor it needs to be ready to change the tiles etc. and I just keep all the tiles to themselves.

  However, in the game itself, I don't want to have to do this. The tiles aren't going to need changes or do anything but be displayed really, and so I'd prefer not to have to make that many draw calls (which leads to lower performance). My maps can have a lot of tiles, so it would certainly be beneficial in my opinion to simply have some big (or maybe even just one?) cobbled together textures to reduce the amount of draw calls.

  Is this correct, and if so, is there a means to do so? I haven't been able to find anything on the subject.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10396
    • View Profile
    • development blog
    • Email
Re: A way to cobble sprites?
« Reply #1 on: April 08, 2014, 07:03:07 pm »
You'll want to use a vertex array, see the dedicated tutorial. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://dev.my-gate.net/

Austin J

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: A way to cobble sprites?
« Reply #2 on: April 08, 2014, 09:56:20 pm »
That's a perfect tutorial, thank's exploitr ;)

Austin J

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: A way to cobble sprites?
« Reply #3 on: April 09, 2014, 06:35:08 pm »
Erm, actually, I may still have an issue here, sorry :/

  The problem I see with this is that it seems to only work if all of your tiles are within a single spritesheet. For our game this simply was not viable. I.e a tile can load random variants in a spritesheet dedicated to that tile, automatically keeping terrain from looking homogeneous. Using a giant sprite sheet for this wasn't viable.

  Is there a way I can get around this dilemna of using different png's rather than just using texture rects?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: A way to cobble sprites?
« Reply #4 on: April 09, 2014, 06:42:22 pm »
The best you can do is 1 draw call (1 vertex array) per texture.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: A way to cobble sprites?
« Reply #5 on: April 09, 2014, 07:04:42 pm »
It doesn't really matter if you have one sprite sheet or a handful or even a few tens of sprite sheets. What matters is that you don't have many tens or hundreds of sprite sheets (textures).
So just split your images into a few - like sprites A through J on one sheet, K through T on another etc - that should be fine.
Or if you want just one for convenience, then look at something like Thor::BigTexture.

Austin J

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: A way to cobble sprites?
« Reply #6 on: April 09, 2014, 09:57:50 pm »
Joseph, I'm not sure you read what I said with full effort.

We are not going to use a big sprite sheet(s), as it makes what we need/want a lot harder. The only time we use a sprite sheet is when we want random variants of a tile. For example, we have a spritesheet with several versions of an ice tile. Of course it's all loaded as one texture, but when the brush puts ice down, the selected sprites randomly select which version of the ice tile in the sheet to use.

  We will not however, keep every single tile of the entire game in one monstrous sprite sheet, for us that's simply a horrible idea.

  I may just be out of luck here?

Sqasher

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: A way to cobble sprites?
« Reply #7 on: April 09, 2014, 11:03:05 pm »
It's the simplest way of doing it.

If you want to keep the textures seperated, you could "stitch" them together at runtime. So when the game starts you load all texturefiles, build a big texturefile out of them and use that in combination with a vertex array. You can use the copy function of sf::Image for that. Minecraft uses this approach too.

Austin J

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: A way to cobble sprites?
« Reply #8 on: April 09, 2014, 11:34:12 pm »
@Squasher, it's not the best way of doing it in our case however.

I'm looking around some more, sf::RenderTexture may be what I need actually.

Insentience

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: A way to cobble sprites?
« Reply #9 on: April 13, 2014, 03:04:06 am »
I'm looking around some more, sf::RenderTexture may be what I need actually.
Yeah this is the solution I would go for

On loading the map, draw each tile once to a separate RenderTexture, then on each frame redraw this prepared RenderTexture to the window