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

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

0 Members and 1 Guest are viewing this topic.

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: 'Tiled' Tile-map Loader
« Reply #180 on: September 11, 2014, 01:01:21 pm »
If you don't know C++ this probably isn't going to be very easy.

Firstly you need to find or build a compatible binary for zlib.
Optionally you need to build box2D.

Afterwards you can either use the included cmake file to configure a VS2013 project which will build a binary you can link to, or you can add the source files directly to your project. Either way you will also need to link zlib (and box2D if you are using it).

eyeliner

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: 'Tiled' Tile-map Loader
« Reply #181 on: September 11, 2014, 04:22:32 pm »
Thought so. Way too freakingly complicated for my dumb self.

I tried but i have no idea about C-Make and all that jazz.  :(
Guess this one is not for me.

Kurangceret

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: 'Tiled' Tile-map Loader
« Reply #182 on: October 11, 2014, 05:20:48 pm »
So far I have linked the zdlib onto my project and included the .h file from the 'tmx and pigixml' folder with the .cpp files added directly into my project. The error I get however was like this
(click to show/hide)

Any solution?

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: 'Tiled' Tile-map Loader
« Reply #183 on: October 12, 2014, 10:42:02 am »
That's a linker error suggesting zlib is not correctly linked. Double check the library paths in your project settings, and make sure zlib.lib is named explicitly in the file list (in both debug and release modes)

xerca

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: 'Tiled' Tile-map Loader
« Reply #184 on: October 18, 2014, 12:07:33 am »
First of all, thank you for this great map loader! I'm using it in my game project and it works really well. Except, I have a problem now that I couldn't solve.

If I understand correctly, the Intersects method in MapObject class is supposed to return true when the two MapObjects have overlapping area, false otherwise. At least that is how I expected to use it. However, it gives random results for me.
The code I wrote looks like this:
(click to show/hide)
This method is called everytime I press "E".

I recorded an example of how it behaves: http://gfycat.com/PerkyIncredibleHeron Here the red box is the DebugShape of interactBox, the gray boxes are the objects in the "interactions" layer of the map. The first sign  I am trying to interact is named "sign1" and the gray box at the top that I can interact without even touching is named "rect1".

It seems I have done something wrong and I just can't figure out why! I have poor programming skills despite coding for many years so it would be very nice if whoever understands my problem explains it to me in a simple way. Thank you in advance!

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: 'Tiled' Tile-map Loader
« Reply #185 on: October 19, 2014, 02:10:16 pm »
This is probably a bug in the intersects() function (I've not had time to work on this for ages, and the bugs are really beginning to build up :/). An alternate approach I've applied in the past is to allocate a list of points to a player / sprite, then check each one to see if it is contained within a map object. Something like:

class Player
{
...

private:
    std::array<sf::vector2f, 4u> m_points = {{-0.5f, -0.5f}, {0.5f, -0.5f},  {0.5f, 0.5f}, {-0.5f, 0.5f}};
};

...

Player::interact()
{
    for(const auto& o : layer.objects())
    {
        for(const auto& p : m_points)
        {
            if(o.contains(getTransform().transformPoint(p))) collide();
        }
    }
}
 

Also, I might suggest (assuming you get this to work) using the quad tree class, or some other partitioning method to reduce the number of objects you test for collision :)

xerca

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: 'Tiled' Tile-map Loader
« Reply #186 on: October 19, 2014, 06:22:19 pm »
To be honest I was already using four points for my characters to handle obstacles while walking but I wanted the player to be able to interact with characters in the same way. Since I couldn't check two sets of points against each other, I decided to use MapObjects instead. Now that you said there is probably a bug, I got more confident in my code and looked thoroughly at the MapObject class to find out what happens exactly.

I found the problem to be in the "SetPosition" or more precisely the "move" method of MapObject:
(click to show/hide)
It moves the points of the map object as well as the position vector whereas the points are supposed to be relative to the position vector of the object. This results in the actual shape being moved twice as much from where it was before. Simply commenting those two lines solved my problem. Thank you!
« Last Edit: October 19, 2014, 06:24:13 pm by xerca »

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: 'Tiled' Tile-map Loader
« Reply #187 on: October 19, 2014, 06:58:39 pm »
Ah! OK, thanks :) I shall add it to the bug list (which I shall sit down and tackle one day :) )

Sehyo

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: 'Tiled' Tile-map Loader
« Reply #188 on: November 06, 2014, 02:11:08 pm »
Hi,
How do I update the drawingbounds?
I can't access the method from the mapLoader object.
Thanks

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: 'Tiled' Tile-map Loader
« Reply #189 on: November 06, 2014, 03:08:17 pm »
iirc it's used internally and automatically called during drawing, so you don't need to call it yourself

Sehyo

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: 'Tiled' Tile-map Loader
« Reply #190 on: November 06, 2014, 04:47:13 pm »
Oh, how would I go on about changing what region of the map it's drawing? So when I move the player the view follows >.<

Thanks

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: 'Tiled' Tile-map Loader
« Reply #191 on: November 06, 2014, 05:53:22 pm »

Sehyo

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: 'Tiled' Tile-map Loader
« Reply #192 on: November 07, 2014, 02:55:13 pm »
use a view as you normally would

http://sfml-dev.org/tutorials/2.1/graphics-view.php

Ah thank you.
I'm new to sfml, didn't realise it had an inbuilt "camera" and thought Id have to change whats drawn manually.
Thanks.

OualidH38

  • Newbie
  • *
  • Posts: 46
    • View Profile
    • Email
Re: 'Tiled' Tile-map Loader
« Reply #193 on: December 02, 2014, 07:05:59 pm »
Hi everybody,

I recently interested in using Tiled with SFML and I am looking for a small sample of code before using it, who shows me how to display a tilemap from a Tiled file and how to handle collision with a little rectangle and the tilemap.

Can you help me please?

Thank you in advance.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: 'Tiled' Tile-map Loader
« Reply #194 on: December 02, 2014, 08:42:42 pm »
Assuming that Tiled can output a comma-separated list, you should be able to simply use the code from this tutorial to display the map and replace the level[] array values with that list. You will probably have to change the tile map parameters too (e.g. tile size, map size).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*