Tilesets
CullenDAvello (18)

OK I've been making a game for a little bit, lots of rectangles not many patterns so I've finally decided to use a tile set but i don't know how can anyone help? i have the file but i don't know how to incorporate it, can anyone help?
----here's my game

!!!! file can be found in assets>PNG's>Dungeon_Tileset.png

A side-note to @SPQR i have been very inactive recently but i'm back now if anyone could help, it would be you.

You are viewing a single comment. View All
mwilki7 (382)

It will take a bit of time nailing all the coordinates for your tileset but once you find all the coordinates it shouldn't be a problem.

After taking a look at the documentation, you should be able to use your tileset by:

  • loading the texture
  • convert from texture to sprite
    • sizing the sprite
  • drawing the sprite

Declared variables:

sf::Texture texture;
RenderWindow window(...);

For loading:

if (!texture.loadFromFile("image.png"))
{
    // error...
}

For converting:

sf::Sprite sprite;
sprite.setTexture(texture);

For sizing:

// sf::Sprite::setTextureRect(); this can take rectangles for parameters
// x = 10, y = 10, width = 32, height = 32
sprite.setTextureRect(sf::IntRect(10, 10, 32, 32));

For drawing:

window.draw(sprite);

It is recommended you separate your different objects into classes. These classes can take care of initialization so you don't have to rewrite your own sprite instances for every new type of object.

Reference:
https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php