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

Author Topic: 'Tiled' Tile-map Loader  (Read 200879 times)

0 Members and 2 Guests are viewing this topic.

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: 'Tiled' Tile-map Loader
« Reply #105 on: December 20, 2013, 10:24:37 am »
Not sure you're looking at the current version.

In m_AddTileToLayer()


        layer.vertexArrays[m_tileInfo[gid].TileSetId].append(v0);
        layer.vertexArrays[m_tileInfo[gid].TileSetId].append(v1);
        layer.vertexArrays[m_tileInfo[gid].TileSetId].append(v2);
        layer.vertexArrays[m_tileInfo[gid].TileSetId].append(v3);
 

In draw()


        states.texture = &m_tilesetTextures[i];
        rt.draw(layer.vertexArrays[i], states);
 

Individual sprites are stored for tiles during loading, but they are only ever drawn by objects which are of type Tile, and image layers which consist of a single sprite.

EDIT: On reflection object layers which use a lot of tiles could benefit from also using vertex arrays - but it may involve a considerable rewrite when taking into account transforms such as flipping / rotating objects which is a feature that should be added to Tiled soon. This would be much easier to handle using sprites.
« Last Edit: December 20, 2013, 12:03:02 pm by fallahn »

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: box2D parsing
« Reply #106 on: December 26, 2013, 08:32:59 pm »
I don't know how many people use box2D in their projects (certainly no one has asked for this) but I thought I'd add this feature anyway. You can now create box2D physics bodies from tmx map objects - here's a demo vid:



I wrote a bit about it on my blog, and uploaded the class to the github page.

blackwave

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: 'Tiled' Tile-map Loader
« Reply #107 on: January 12, 2014, 01:46:32 am »
Hi,

This project looks awesome. I'm trying to compile it on Linux and having some trouble. Specifically, I get the following error;
Code: [Select]
src/MapObject.cpp:220:37: error: non-const lvalue reference to type
      'Vector2<[...]>' cannot bind to a temporary of type 'Vector2<[...]>'
        return Helpers::Vectors::Normalize(end - start);
                                           ^~~~~~~~~~~
/home/cole/Desktop/sfml-tmxloader/include/Helpers.h:70:47: note: passing
      argument to parameter 'source' here
                static sf::Vector2f Normalize(sf::Vector2f& source)
                                                            ^
1 error generated.

Which is associated with this function:
Code: [Select]
sf::Vector2f MapObject::CollisionNormal(const sf::Vector2f& start, const sf::Vector2f& end) const
{
Segment trajectory(start, end);
for(auto& s : m_polySegs)
{
if(trajectory.Intersects(s))
{
sf::Vector2f v = s.End - s.Start;
sf::Vector2f n(v.y, -v.x);
//invert normal if pointing in wrong direction
float tAngle = Helpers::Vectors::GetAngle(end - start);
float nAngle = Helpers::Vectors::GetAngle(n);
if(nAngle - tAngle > 90.f) n =- n;

return Helpers::Vectors::Normalize(n);
}
}
return Helpers::Vectors::Normalize(end - start);
}

I have limited experience with C++, and I don't know what this code is supposed to do, but I was able to make the code compile by changing the second return line to:
Code: [Select]
return sf::Vector2f(0,0);

The examples seem to work with this code (although it's probably doing something horrendous somewhere; I don't know).

Is this problem just on my end? Am I doing something incorrectly? Thanks.

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: 'Tiled' Tile-map Loader
« Reply #108 on: January 12, 2014, 09:37:16 am »
Hi, a lot of the collision stuff is not thouroughly tested - I don't even have a linux machine right now - so this may well be a  bug. Try constructing a new vector from end-start and return that via normalize and let me know if it works. I'll make a note of it on the tracker.

Sixoul

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: 'Tiled' Tile-map Loader
« Reply #109 on: January 21, 2014, 12:10:21 am »
How would I get an affect of walking in grass similar to Pokemon?



The character's legs disappear in the grass but their upper half is still visible. Is this possible with tiled and your map loader?

MadMartin

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: 'Tiled' Tile-map Loader
« Reply #110 on: January 21, 2014, 08:57:52 am »
For that you have to have the sprite separated in two halfs (upper and lower body). Just check if the sprite is drawn onto a tile where semi-high things are (grass, snow, etc.) and only draw the upper body.

Not sure if this is possible with this map loader, but it is not that difficult in general.

Sixoul

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: 'Tiled' Tile-map Loader
« Reply #111 on: January 21, 2014, 09:55:14 am »
That's what I was discussing with a friend and we came to the conclusion it would have to be a sprite split in half.
Thanks.

cyberpala

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: 'Tiled' Tile-map Loader
« Reply #112 on: February 09, 2014, 02:20:16 pm »
@fallahn

Hello I'm new here , started programming with C++/SFML. I want to try out your loader with the benchmark example. (VC2013) What have I do to compile the Benchmark example. (always get linker Errors)

The SFML intergration in VC2013 works.

Thanks

cyberpala

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: 'Tiled' Tile-map Loader
« Reply #113 on: February 09, 2014, 02:39:29 pm »
What linker errors do you get? The map loader needs to be linked against zlib as well as sfml

Ricky

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
    • Tejada
    • Email
Re: 'Tiled' Tile-map Loader
« Reply #114 on: March 23, 2014, 07:55:13 pm »
Hello,

Sorry to bother, I'm interested in the project and I'd like to learn how to use it however I can't even get it built!
It's probably something wrong on my side but here is the error cmake is giving me:

CMake Error at CMakeLists.txt:32 (install):
  install Library TARGETS given no DESTINATION!


CMake Error at cmake/Modules/FindSFML.cmake:307 (message):
  Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY
  SFML_GRAPHICS_LIBRARY)
Call Stack (most recent call first):
  CMakeLists.txt:40 (find_package)
Wilt thou yet say before him that slayeth thee, I am God? but thou shalt be a man, and no God, in the hand of him that slayeth thee.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Re: 'Tiled' Tile-map Loader
« Reply #115 on: March 23, 2014, 08:31:26 pm »
CMake Error at cmake/Modules/FindSFML.cmake:307 (message):
  Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY
  SFML_GRAPHICS_LIBRARY)
Call Stack (most recent call first):
  CMakeLists.txt:40 (find_package)
It doesn't find SFML. You need to set SFML_ROOT in CMake to the root dir of SFML.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

crypto

  • Guest
Re: 'Tiled' Tile-map Loader
« Reply #116 on: March 24, 2014, 03:57:14 am »
Hey,

There seems to be a bug in

TileQuad::Ptr MapLoader::m_AddTileToLayer(MapLayer& layer, sf::Uint16 x, sf::Uint16 y, sf::Uint32 gid, const sf::Vector2f& offset)

Where you do

//applying half pixel trick avoids artifacting when scrolling
v0.texCoords = m_tileInfo[gid].Coords[0] + sf::Vector2f(0.5f, 0.5f);
v1.texCoords = m_tileInfo[gid].Coords[1] + sf::Vector2f(-0.5f, 0.5f);
v2.texCoords = m_tileInfo[gid].Coords[2] + sf::Vector2f(-0.5f, -0.5f);
v3.texCoords = m_tileInfo[gid].Coords[3] + sf::Vector2f(0.5f, -0.5f);

If I run it as is, all my tiles have a half-pixel weirdness to them, but if I remove the extra half pixels, it works perfectly. I tried with tilesets that have no margin/padding and some that have a margin/padding, it happens with both. I'm using SFML-master (today's snapshot) and MinGW 4.8.1.

Before / After
« Last Edit: March 25, 2014, 04:19:34 am by crypto »

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: 'Tiled' Tile-map Loader
« Reply #117 on: March 24, 2014, 10:42:48 am »
What happens when you scroll your view? The half pixel fix only really applies when a view is scaled or scrolled. How do the examples look when you compile them? They work fine on every machine I've tested, but I haven't performed an exhaustive set of tests. If the examples also exhibit this behaviour for you then it may be a graphics driver issue

crypto

  • Guest
Re: 'Tiled' Tile-map Loader
« Reply #118 on: March 24, 2014, 02:07:31 pm »
I tried Benchmark.cpp and the issue is still present. However, if I remove the half pixels and maximize the window, scrolling will sometimes vertical gaps, is that what you meant?

I'll look at it more when I get back from work. I'm running Win8 64 bits with a Radeon HD5850, latest drivers.

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: 'Tiled' Tile-map Loader
« Reply #119 on: March 24, 2014, 03:59:31 pm »
Yes, the gaps when scrolling is what I mean. It's a well documented artifact using vertex arrays (there are several posts on the forum about it). I don't have access to a Win8 machine, but I do have my suspicions about the latest AMD driver. When I updated from 13.9 to 13.12 on 2 machines I found that 1 in 3 times (more or less) I couldn't even create an SFML window without it hanging on a white screen. Updating to the latest beta drivers fixed this. AMD are obviously working on updating their OpenGL implementation too, as updating the drivers broke a few of my shaders which, as it turned out, was due to my shader code not being as strictly adherent to GLSL as they should be (so in this case the AMD update is a good thing). I'm not sure what to suggest as a fix unfortunately.