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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - mflash

Pages: [1]
1
SFML projects / Re: 'Tiled' Tile-map Loader
« on: September 14, 2013, 08:25:16 pm »
Well, in fact I'm trying to get an undergraduate class to understand the basic principles of collision detection in games, so a tile layer with collision info seemed to be the easiest way. It's also very quick to put it together in Tiled, for instance. But of course you're right: it depends on the particular application. A quadtree is usually a sensible idea, but it just seemed overkill in my case  :)

2
SFML projects / Re: 'Tiled' Tile-map Loader
« on: September 13, 2013, 02:08:10 pm »
Glad to be of help  :)

I have another quick question for you: I'm trying to check for collisions between a sprite and a collision layer of tiles, but your MapTile struct doesn't store the GID of a tile. Hence I added a gid field to the struct as follows:

struct MapTile
{
        //returns the base centre point of sprite / tile
        const sf::Vector2f GetBase(void) const
        {
                return sf::Vector2f(sprite.getPosition().x + (sprite.getLocalBounds().width / 2.f),
                sprite.getPosition().y + sprite.getLocalBounds().height);
        }
        sf::Sprite sprite;
        sf::Vector2i gridCoord;
        sf::Uint16 gid; // need gid to check contents
        sf::RenderStates renderStates; //used to perform any rendering with custom shaders or blend mode
};
 

What do you reckon? Is that a sensible approach?

Cheers!

3
SFML projects / Re: 'Tiled' Tile-map Loader
« on: September 07, 2013, 07:15:44 pm »
Matt, first of all thanks for your code. It works really well!

I've just found a little bug when you compute the number of rows and columns in MapLoader::m_ProcessTiles:

const bool MapLoader::m_ProcessTiles(const pugi::xml_node& tilesetNode)
{
        sf::Uint16 tileWidth, tileHeight, spacing, margin;
        ...
        //slice into tiles
        int columns = sourceImage->getSize().x / tileWidth;
        int rows = sourceImage->getSize().y / tileHeight;
 

This won't take into account the spacing and margin of the tileset, if any. I've discovered by accident, trying to load a map with the blocks1.png tileset (attached below). That tileset requires a margin and spacing of 2 pixels.

The fix is easy:

const bool MapLoader::m_ProcessTiles(const pugi::xml_node& tilesetNode)
{
        sf::Uint16 tileWidth, tileHeight, spacing, margin;
        ...
        //slice into tiles
        int columns = (sourceImage->getSize().x-margin) / (tileWidth+spacing);
        int rows = (sourceImage->getSize().y-margin) / (tileHeight+spacing);
 

Hope it helps  :)

Cheers!

Pages: [1]
anything