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

Author Topic: Sorting sprite's layers in isometric view  (Read 5015 times)

0 Members and 4 Guests are viewing this topic.

zbrojny120

  • Newbie
  • *
  • Posts: 3
    • View Profile
Sorting sprite's layers in isometric view
« on: March 28, 2015, 11:32:40 pm »
I'm making a strategy game with isometric view and I'm having some problems with deciding which sprite should be drawn first (I'm using SFML 2.2 as graphic library). I'm using std::sort to sort sprites in array by their Y position in a window (Floor and walls aren't sorted, they are stored in different arrays). This code works well in an RPG game where there aren't more than 100 sprites on the map at the same time, but this is going to be a strategy game and when there are 13000 or more sprites on the map, FPS is dropping below 30 and game is becoming unplayable. So, is there any faster way to sort these sprites?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Sorting sprite's layers in isometric view
« Reply #1 on: March 29, 2015, 12:03:00 am »
I've never written my own isometric game, as such I've not done any research on good data structures and how to sort things, however since it's a quite popular topic, there should be lots of information on the internet. Did you spend some time looking for such information/examples?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

zbrojny120

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Sorting sprite's layers in isometric view
« Reply #2 on: March 29, 2015, 12:20:28 pm »
Yes, I did, but there wasn't any tutorial saying how to exactly sort these sprites (I'm fairly new to programming).

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Sorting sprite's layers in isometric view
« Reply #3 on: March 29, 2015, 12:53:54 pm »
There will most likely never be any exact tutorial on how to sort sprites. Sorting STL containers is a general subject and hence you should learn about that. Then you can apply that to sorting sprites (or more exactly, you will be sorting your own objects that contain the depth information).

https://www.google.com/search?q=std%3A%3Asort+container
http://www.cplusplus.com/articles/NhA0RXSz/
http://www.cplusplus.com/reference/algorithm/sort/
« Last Edit: March 29, 2015, 12:55:32 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Sorting sprite's layers in isometric view
« Reply #4 on: March 29, 2015, 01:39:44 pm »
do you resort everything every frame? cant you keep a small list of which objects to draw first, containing only the nearest objects?
then you just update the list when you go to the next chunk of tiles.
Visit my game site (and hopefully help funding it? )
Website | IndieDB

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: Sorting sprite's layers in isometric view
« Reply #5 on: March 30, 2015, 09:07:40 am »
To me it doesn't sound like a sorting problem. It sounds more like a problem with how many sprites you try to draw individually.
Did you profile to check if the sorting is really your problem?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Sorting sprite's layers in isometric view
« Reply #6 on: March 30, 2015, 01:11:54 pm »
Take a look here: http://www-cs-students.stanford.edu/~amitp/gameprog.html#tiles and youll find lots of resources on isometric tile based games.
For more general good stuff, check out this link: http://www.redblobgames.com/

zbrojny120

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Sorting sprite's layers in isometric view
« Reply #7 on: March 30, 2015, 04:06:45 pm »
To me it doesn't sound like a sorting problem. It sounds more like a problem with how many sprites you try to draw individually.
Did you profile to check if the sorting is really your problem?

Yes, with disabled sorting there are no problems.

Take a look here: http://www-cs-students.stanford.edu/~amitp/gameprog.html#tiles and youll find lots of resources on isometric tile based games.
For more general good stuff, check out this link: http://www.redblobgames.com/

Thanks, I will definitely check these