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

Author Topic: Tile-based graphic using Sprites.. right?  (Read 2620 times)

0 Members and 1 Guest are viewing this topic.

LakySimi1

  • Newbie
  • *
  • Posts: 35
    • View Profile
Tile-based graphic using Sprites.. right?
« on: May 06, 2024, 07:13:07 pm »
Hi everyone,
assuming that i want to make a 2D tile-based game, such as Avadon or Fallout 1/2, in which roofs can disappear to let look inside buildings (like Fallout 1/2), or in which different tiles get darkened depending if they are visible or not to player (like Avadon) (for example), is it right to use Sprites for substantially everyting?

for(each tile to show)
{
    Sprite.setTextureRect(sf::IntRect(x,y,z,k));    //Get tile
    Sprite.setPosition(sf::Vector2f(i.f,j.f));      //Draw coordinates
    Sprite.setColor(sf::Color(255, 255, 255));      //Light
    window.draw(Sprite);                            //Render
}



Avadon
(click to show/hide)
Fallout
(click to show/hide)
« Last Edit: May 06, 2024, 07:15:15 pm by LakySimi1 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Tile-based graphic using Sprites.. right?
« Reply #1 on: May 08, 2024, 08:18:31 am »
The term you're looking for is "isometric".

You can use sprites, but you may run into performance issues down the line, so you may consider starting off with vertex arrays.

The difficult part is correctly calculating which tile needs to be rendered on top of what other tile, depending if something is below or above or infront.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

LakySimi1

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Tile-based graphic using Sprites.. right?
« Reply #2 on: May 08, 2024, 09:20:47 pm »
I think yes but i didn't use "isometric" since is perspective-related and not necessarily tile-related.

Thank you! Searching online i've found this https://www.sfml-dev.org/tutorials/2.4/graphics-vertex-array.php , i think is exctly what i was looking for probably, rigt?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Tile-based graphic using Sprites.. right?
« Reply #3 on: May 09, 2024, 09:51:46 am »
When talking about tiling it's mostly thought of as a flat 2D space. Isometric rendering requires a lot of special rules, that on a 2D grid doesn't necessarily apply, thus my suggestion to search more around the term isometric.

Searching online i've found this https://www.sfml-dev.org/tutorials/2.4/graphics-vertex-array.php , i think is exctly what i was looking for probably, rigt?
Yes, this shows you how to utilize a vertex array.

This might also be useful: https://www.binpress.com/creating-city-building-game-with-sfml/
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

LakySimi1

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Tile-based graphic using Sprites.. right?
« Reply #4 on: May 12, 2024, 10:22:53 pm »
Thank you very much for the resources!