Representing a route graph

33 views
Skip to first unread message

Pito

unread,
Feb 6, 2012, 2:46:29 PM2/6/12
to Tiled Map Editor
Hi all,

I continue to have great success with Tiled. Nice app!

I want to represent a standard traveling route as an overlay over my
map, using objects.

I could individually mark each node as an object, and then manually
indicate the connections through handcrafted xml. But that's a pain.

Or I could try using a bunch of separate lines indicating each edge
with the end points being the nodes. But then it takes work to tell
that edge1 and edge2 share a node.

Or I could try using a polyline or polygon, but then I can't represent
a general graph.

Is there a better way?

Thanks!

Pito

Thorbjørn Lindeijer

unread,
Feb 6, 2012, 3:52:12 PM2/6/12
to mape...@googlegroups.com
Hello Pito,

On Mon, Feb 6, 2012 at 20:46, Pito <pito...@gmail.com> wrote:
> I continue to have great success with Tiled. Nice app!

Great to hear! :-)

> I want to represent a standard traveling route as an overlay over my
> map, using objects.
>
> I could individually mark each node as an object, and then manually
> indicate the connections through handcrafted xml. But that's a pain.
>
> Or I could try using a  bunch of separate lines indicating each edge
> with the end points being the nodes. But then it takes work to tell
> that edge1 and edge2 share a node.
>
> Or I could try using a polyline or polygon, but then I can't represent
> a general graph.
>
> Is there a better way?

Unfortunately this isn't a use-case that is covered by the
polygon/polyline feature, as you have discovered. General graphs would
need to be stored rather differently since they can't be represented
simply by a list of points, but rather need a list of points + a list
of connections between these points. I have currently no plans for
expanding the polygon/polyline feature to graphs, though it would of
course be possible.

I guess one way of representing graphs is to use filled polygons to
mark all the non-passable areas, so that what remains are the routes
you are looking for, but I'm sure this fits right into that list of
non-perfect solutions you had already.

Another option would be to use the polyline feature and then after
loading the map, process all your polylines to generate the list of
unique points and the connections between them. Extracting your graph,
so to speak. This should work fine especially when using the
snap-to-grid feature to make sure the points of the polyline are
exactly aligned. When you really need freely positioned points, you
could try to add a snap-to-point feature to Tiled, which should be
easy compared to adding full graph editing.

Best regards,
Bjørn

Pito

unread,
Feb 6, 2012, 5:16:52 PM2/6/12
to Tiled Map Editor
Hi Bjørn

Thanks... The polyline idea might work well. With the snap to grid
feature I could solve the problem that I saw which was how to tell
that node a and a' part of two different polylines were actually the
same point. Another idea would be that on import into my game I could
allow a small delta to decide that two nodes were actually the same
point...

By the way, I didn't see the snap to grid feature for the polyline and
polygon. In fact I only accidentally discovered that if I hold down
control I could place points off the tile grid, in other words,
without control I seem to only be able to place points on the corners
of the tiles.

Which leads me to ask whether you wrote down info about those features
anywhere because I looked around the wiki and didn't see anything. I
am sure there may be other features hiding that I don't realize are
there :)

Thanks,

On Feb 6, 3:52 pm, Thorbjørn Lindeijer <thorbj...@lindeijer.nl> wrote:
> Hello Pito,
>

Thorbjørn Lindeijer

unread,
Feb 6, 2012, 6:00:21 PM2/6/12
to mape...@googlegroups.com
On Mon, Feb 6, 2012 at 23:16, Pito <pito...@gmail.com> wrote:
> By the way, I didn't see the snap to grid feature for the polyline and
> polygon. In fact I only accidentally discovered that if I hold down
> control I could place points off the tile grid, in other words,
> without control I seem to only be able to place points on the corners
> of the tiles.

In fact the 'Snap to Grid' toggle in the View menu also works for
nodes on polylines/polygons.

> Which leads me to ask whether you wrote down info about those features
> anywhere because I looked around the wiki and didn't see anything. I
> am sure there may be other features hiding that I don't realize are
> there :)

There is a page about shortcuts on the wiki, but Tiled doesn't have a
completely manual yet (not even much of a start). This is a bit
embarrassing, but I still plan to get around to it at some point...

Best regards,
Bjørn

Pito Salas

unread,
Feb 6, 2012, 6:06:56 PM2/6/12
to mape...@googlegroups.com
Bjørn

No problem about not having doc, I know how it goes :)

As far as the grid is concerned is it possible to have a different
grid apply to the objects as does to the tiles? In my case I need a
grid that's 4 times finer for the objects as for the tiles?

Thanks,

Pito

2012/2/6 Thorbjørn Lindeijer <thor...@lindeijer.nl>:

> --
> Tiled Map Editor mailing list
> mape...@googlegroups.com
> http://groups.google.com/group/mapeditor

--
Check out http://www.salas.com and http://www.blogbridge.com/look

Thorbjørn Lindeijer

unread,
Feb 7, 2012, 3:59:48 AM2/7/12
to mape...@googlegroups.com
On Tue, Feb 7, 2012 at 00:06, Pito Salas <pito...@gmail.com> wrote:
> As far as the grid is concerned is it possible to have a different
> grid apply to the objects as does to the tiles? In my case I need a
> grid that's 4 times finer for the objects as for the tiles?

Not without patching the code at the moment. This is not so hard as it may seem.

The code that would require modification is here for editing polygons:

https://github.com/bjorn/tiled/blob/master/src/tiled/editpolygontool.cpp#L507

And here for creating polygons:

https://github.com/bjorn/tiled/blob/master/src/tiled/createobjecttool.cpp#L148
https://github.com/bjorn/tiled/blob/master/src/tiled/createobjecttool.cpp#L227

Of course that won't change grid rendering, but changing the simple
rounding to a rounding after multiplying by 4 and then dividing by 4
again would give you the behavior you're looking for.

Best regards,
Bjørn

Reply all
Reply to author
Forward
0 new messages