Cannot get Tiled collision definition to show as Dusk physics

Hi there. I’m considering going from my own tile system to something more sensible, like a Tiled / Dusk combo, but I cannot get even the simplest stuff right ti seems.

I’ve tried to create a simple map with Tiled and defined collision data for each tile in the collision editor. Data can be found here:

g03.json

soil_map_hq_128.png

soil_map_hq_128_rot.png

Then I’ve tried to make an übersimple app that shows this map with hybrid drawing mode to see how the physics is working, but there doesn’t seem to be any?

local dusk = require("Dusk.Dusk") require("physics") physics.start() physics.setDrawMode("hybrid") display.setDefault("minTextureFilter", "nearest") display.setDefault("magTextureFilter", "nearest") local map = dusk.buildMap("maps/g03.json") map.x = 0 map.y = 0 local mapPixSize = display.contentWidth\*2 map.width = mapPixSize map.height = mapPixSize local function gameLoop(event) map.updateView() end Runtime:addEventListener("enterFrame", gameLoop)

Anyone know how this is supposed to work? Maybe there are some simple examples I can look at somewhere?

Can you show where you are adding physics bodies to your tiles?

Do you mean in the Corona code or in Tiled?

Are you using Tiled’s physics editor? Dusk doesn’t currently support complex bodies like Tiled allows in collision editing. You can see how Dusk handles physics in the FAQ. http://rawgit.com/GymbylCoding/Dusk-Engine/master/docs/guides/faq.html#add-physics

Also… I wouldn’t really consider physics polygon triangulation and auto bodies übersimple, to be honest, but hey… to each his own definition of übersimple. :smiley:

  • Caleb

Ahh… I think I have royally misunderstood what Dusk is. I thought it was some kind “Corona support for Tiled projects”. I was hoping that I could do most of the level design in Tiled, but I see now that Dusk is supporting a small subset of what is possible in Tiled.

I’m doing a “cave” game and use quite “complex” / numerous tiles to be able to construct the levels so it isn’t too obvious that they are made of tiles…:

(I have to to twice as many tiles as this, because Dusk doesn’t support rotation)

From the docs it not clear to me how the shape of the physics bodies are defined. Do you maybe mean the hard way (by writing coordinates by hand)? Or is there some info that I haven’t completely been able to extract?

Because doing the physics bodies of my tiles by hand… oh boy…  :rolleyes:

>Also… I wouldn’t really consider physics polygon triangulation and auto bodies übersimple, to be honest, but hey… to each his own definition of übersimple

It was the 16 lines example app that was simple  :stuck_out_tongue:

Sorry about the misunderstanding. Dusk definitely doesn’t support everything about Tiled. While I would love Dusk to be a full implementation of Tiled (and, really, it’s not really a small subset - all of the biggest features of Tiled are supported), keep in mind that my work on Dusk is completely volunteered. I’m coding on Dusk in much of my free time (the rest of which I devote to piano, music composition, and reading), and many Corona users use it and love it. That said, no one pays for it. Making Dusk free was a decision I made willingly when I started it and which I won’t be changing anytime soon, but still, it means that my personal projects (like a game that’s been my childhood dream ever since I started playing games that’s been about 8 years in the concept phase and which I’m only just starting to realize with the help of Corona and Dusk) come first. I am doing my very best to make Dusk a capable and usable tool for Tiled implementation, and it’s working very well in my game. Dusk 1.0 is coming soon, and small Tiled features like tile rotation as well as good documentation will come. I feel for your frustration. Please try to be patient. Many Corona users use Dusk, but only I maintain it and develop new features for it. I’ve just been in China, had to practice like crazy for a state piano competition (of which I was one of the 7 winners, if you’ll permit me to brag a bit), and on top of that, I’m still in high school so I have school work to deal with every day as well as preparations for my graduation this summer. Sorry for unloading on you, it’s just that I’ve been super (or should I say über- :D) stressed lately and have a lot on my plate.

In the meantime, unfortunately, physics bodies must be specified with physics:shape and a table. I guess that’s the point of my whole post, really ;)…

physics:shape : !!! 1,1, 10,10, -10,10
  • Caleb

Hey, Caleb, sorry if I came through as ungrateful. I’m absolutely not. I just didn’t have a complete understanding of what Dusk was.

Nobody has the right to complain about something that is free (but somebody does anyway (I know as I’ve been on the receiving end more than enough)).

I will find some way to define the physics bodies then. Maybe it’s possible to write something that interprets the json output from Tiled and create those physics:shape lines.

But as you, I have a million other things besides this particular project. That’s why I haven’t been able to study Dusk thoroughly.

It’s definitely possible. To code a plugin or some such thing for that for the current version of Dusk might be a bit much for all but a power user (sometimes, with the current plugin architecture, I still have to add some tweaks to the library to get more out of Dusk), but a basic implementation of this (no concave polygons; the user’ll have to construct them from the Tiled physics editor) will be in Dusk 1.0.

In the meantime, you could try writing a superbly hacky method to load up the physics data yourself. It’s stored weirdly in Tiled’s format as an objectgroup, so you’d have to examine the map file to understand the structure. Dusk’s plugin architecture is really basic, but you can create property prefixes through it. That means you can write a function to convert values prefixed with a tag to your own type of value. Bleh! That sounds super obtuse and complex, but it’s not really. As I think about it, what you’d need to do is becoming more and more complex in my mind, so if you want more information on it, ask and I’ll give you a tutorial on how to do it. Basically the problem is that Dusk supports physics bodies one at a time in Tiled properties (as physics1: physics2: physics3: etc.). That means to correctly generate the body from Tiled’s collision data, you’d create a prefix method and edit the map properties to look something like this:

physics1:shape : (get Tiled collision data for this tile, body #1) physics2:shape : (get Tiled collision data for this tile, body #2) etc.

If, on the other hand, you’d only be creating a single convex physics shape in Tiled’s collision editor, that would make the method orders of magnitude easier. In that case, let me know and I could even come up with the full code for you, probably.

  • Caleb

Hi Caleb P,

Thanks for the explanation. As you can see from my tile shapes I unfortunately need some kind of concave support. It’s been at least a year since I was working on this game. Embarrassingly enough I don’t remember exactly how I solved the concave problem. I probably just hardcoded several convex shapes to make up a concave shape. Pre-tessellation if you like.

I just found out that this is also possible in Tiled. It seems to be possible to define more than one (collision) polygon per tile. If you make sure all of these are convex, shouldn’t it (in theory) be possible to import and use these as shapes in Dusk?

Maybe something for 1.1? I can wait. I have enough other projects going  :smiley:

As I mentioned in the post above, basic Tiled collision editor support is coming in version 1.0 - this next version. This feature includes multi-element physics bodies with shapes driven from Tiled’s editor data. Dusk will not automatically tessellate polygon shapes, but you will be able to construct concave polygons by building multiple convex ones. Automatic tessellation might come later.

  • Caleb

Collision editor implementation worked really well. I’m now importing the bodies from the collision editor and setting them on tiles as multi-element physics bodies. Here’s a gif of it. I’m kind of wishing I had a project that used Box2D just so I could use this feature :).

  • Caleb

Great, great!

I don’t see the gif, but I’ll take your word for it  :smiley:

Any timeframe regarding when it can be possible to test this? Not that I’m in a hurry…

Sorry, Corona’s forum software coughed it up so I had to put it on DropBox. I’ve edited the post.

I’m in conversation with the Corona engineers about some final questions related to how to get it to users for testing, so when that’s done (potentially super short–say, a couple of days or so), I’ll send it to everyone who opted in to testing. After testing, I have a few wrap-up things like getting at least some semblance of docs written and it’ll be public!

  • Caleb

Can you show where you are adding physics bodies to your tiles?

Do you mean in the Corona code or in Tiled?

Are you using Tiled’s physics editor? Dusk doesn’t currently support complex bodies like Tiled allows in collision editing. You can see how Dusk handles physics in the FAQ. http://rawgit.com/GymbylCoding/Dusk-Engine/master/docs/guides/faq.html#add-physics

Also… I wouldn’t really consider physics polygon triangulation and auto bodies übersimple, to be honest, but hey… to each his own definition of übersimple. :smiley:

  • Caleb

Ahh… I think I have royally misunderstood what Dusk is. I thought it was some kind “Corona support for Tiled projects”. I was hoping that I could do most of the level design in Tiled, but I see now that Dusk is supporting a small subset of what is possible in Tiled.

I’m doing a “cave” game and use quite “complex” / numerous tiles to be able to construct the levels so it isn’t too obvious that they are made of tiles…:

(I have to to twice as many tiles as this, because Dusk doesn’t support rotation)

From the docs it not clear to me how the shape of the physics bodies are defined. Do you maybe mean the hard way (by writing coordinates by hand)? Or is there some info that I haven’t completely been able to extract?

Because doing the physics bodies of my tiles by hand… oh boy…  :rolleyes:

>Also… I wouldn’t really consider physics polygon triangulation and auto bodies übersimple, to be honest, but hey… to each his own definition of übersimple

It was the 16 lines example app that was simple  :stuck_out_tongue:

Sorry about the misunderstanding. Dusk definitely doesn’t support everything about Tiled. While I would love Dusk to be a full implementation of Tiled (and, really, it’s not really a small subset - all of the biggest features of Tiled are supported), keep in mind that my work on Dusk is completely volunteered. I’m coding on Dusk in much of my free time (the rest of which I devote to piano, music composition, and reading), and many Corona users use it and love it. That said, no one pays for it. Making Dusk free was a decision I made willingly when I started it and which I won’t be changing anytime soon, but still, it means that my personal projects (like a game that’s been my childhood dream ever since I started playing games that’s been about 8 years in the concept phase and which I’m only just starting to realize with the help of Corona and Dusk) come first. I am doing my very best to make Dusk a capable and usable tool for Tiled implementation, and it’s working very well in my game. Dusk 1.0 is coming soon, and small Tiled features like tile rotation as well as good documentation will come. I feel for your frustration. Please try to be patient. Many Corona users use Dusk, but only I maintain it and develop new features for it. I’ve just been in China, had to practice like crazy for a state piano competition (of which I was one of the 7 winners, if you’ll permit me to brag a bit), and on top of that, I’m still in high school so I have school work to deal with every day as well as preparations for my graduation this summer. Sorry for unloading on you, it’s just that I’ve been super (or should I say über- :D) stressed lately and have a lot on my plate.

In the meantime, unfortunately, physics bodies must be specified with physics:shape and a table. I guess that’s the point of my whole post, really ;)…

physics:shape : !!! 1,1, 10,10, -10,10
  • Caleb

Hey, Caleb, sorry if I came through as ungrateful. I’m absolutely not. I just didn’t have a complete understanding of what Dusk was.

Nobody has the right to complain about something that is free (but somebody does anyway (I know as I’ve been on the receiving end more than enough)).

I will find some way to define the physics bodies then. Maybe it’s possible to write something that interprets the json output from Tiled and create those physics:shape lines.

But as you, I have a million other things besides this particular project. That’s why I haven’t been able to study Dusk thoroughly.

It’s definitely possible. To code a plugin or some such thing for that for the current version of Dusk might be a bit much for all but a power user (sometimes, with the current plugin architecture, I still have to add some tweaks to the library to get more out of Dusk), but a basic implementation of this (no concave polygons; the user’ll have to construct them from the Tiled physics editor) will be in Dusk 1.0.

In the meantime, you could try writing a superbly hacky method to load up the physics data yourself. It’s stored weirdly in Tiled’s format as an objectgroup, so you’d have to examine the map file to understand the structure. Dusk’s plugin architecture is really basic, but you can create property prefixes through it. That means you can write a function to convert values prefixed with a tag to your own type of value. Bleh! That sounds super obtuse and complex, but it’s not really. As I think about it, what you’d need to do is becoming more and more complex in my mind, so if you want more information on it, ask and I’ll give you a tutorial on how to do it. Basically the problem is that Dusk supports physics bodies one at a time in Tiled properties (as physics1: physics2: physics3: etc.). That means to correctly generate the body from Tiled’s collision data, you’d create a prefix method and edit the map properties to look something like this:

physics1:shape : (get Tiled collision data for this tile, body #1) physics2:shape : (get Tiled collision data for this tile, body #2) etc.

If, on the other hand, you’d only be creating a single convex physics shape in Tiled’s collision editor, that would make the method orders of magnitude easier. In that case, let me know and I could even come up with the full code for you, probably.

  • Caleb