Dusk Engine

I just did a quick test. It appears that the height of a horizontal line is 12 px with virtualObjectsVisible on or off. I posted an issue to your Github project. 

I just posted the code into the issue. I can post my example files if you like. 

Is it possible to set the shape of a physics object via Tiled? Imagine you’ve made an image or tile object on an object layer. You want the shape to be smaller or something other than a rectangle the size of the tile. 

I’m picturing something like the following added to an object in Tiled:

shape = {-10,-10,10,-10,10,10,-10,10}

or 

physics:shape = {-10,-10,10,-10,10,10,-10,10}

Of course neither of these seemed to be working. 

Tables must be added via JSON, which is interpreted only if the value is prefixed with !json!. Somehow, this didn’t get into the docs :slight_smile:

[lua]

physics:shape = !json! [-10,-10, 10,-10, 10,10, -10,10]

[/lua]

  • Caleb

Thanks! That seems to work well. 

Ok!

I think I have found out why it would say that it can’t find the tileset image.

I moved all the tileset images to another folder AFTER the mapname.lua was created.

I just deleted the old lua file containing map information, opened up Tiled and exported it again.

Works now.

Glad you got it sorted :slight_smile:

  • C

What’s the best strategy for removing a map and loading a new map? 

I’m guessing map.destroy() removes everything, including physics objects. Q: does this also include objects added to the map that were not included in the map.json?

Another question: What’s the official name for this library?

I prefer not to waste other people’s time here on the forums, but I’m really having trouble understanding this error:

Dusk Error:

Invalid GID at position [1,9] <index #401> - expected [0 <= GID <= 24] but got 2684354572 instead.

State: Draw Tile <Layer #1 - “Tile Layer 1”>

Traceback: [Base]:[Build Map]:[Register Tile Culling and Camera]

@soggybag:

map.destroy() destroys the map. It should also destroy any added objects (that were added with layer:insert()), as it simply uses a display.remove() for everything (plus some internals).

The official name is “Dusk Engine” (oftentimes with “the” in front of it). When referring to it, you can use either one, though - Dusk or Dusk Engine. If you credit it in your game, use “Dusk Engine” (something like “Utilizes the Dusk Engine”).

The repository hasn’t been renamed, yet, so that might be a cause of confusion :slight_smile:

@tilen.curin:

That error means Dusk came across a GID (which means the identifier of which “slice” of the tileset to draw) that was over or under the range of GIDs. For example, if you have 24 tiles in your tileset (as you seem to), a GID of 25 would throw an error because there aren’t 25 tiles in your tileset.

Your error is likely coming of a flipped or rotated tile. I just pushed a commit that allows flipped tiles (no rotated, yet), so if you download it, flipped tiles should now work.

  • Caleb

Yes, I was flipping tiles. Didn’t think that would be a problem.

Nice, thanks for the update. I’ll download it right away.

I still don’t know what’s causing that “bounce” issue, but I’ve found a way around.

It’s not a problem for my project atm.

So unless someone else is having a similar problem I wouldn’t bother with it anymore.

I was looking at that example game (bob), trying to figure out how to make the player collide with tiles and saw that you’ve added some properties to some tiles in Tiled (bodyType, physics:bounce and physics:enabled).

Is there anything else that you must do to add physics bodies to tiles?

I’ve also noticed that you have added some map properties (player and finish locations) with value !json! followed by the coordinates.
What should I do if I’m using .lua format for my map? In the api it says that Dusk supports .lua maps.

I want to get the tile at an x and y on a map. Using map.layer[“a”].tile( 10, 10 ). It seems tiles don’t exist when they are culled, so you can’t get at a tile if it’s off screen. This is not a big deal, but it would be great if you could get the data about this tile that was loaded from the map.json. I could load this data, but it seems that it’s already in Dusk, so the info is already there. Is it posible to get to this? 

I’m working on a platform type game. I’m running into trouble using physics. So I thought I’d give a go at creating getting this working without physics. To get this working I’d need to know which tile is at any x and y position on the map. 

Poking around I find a tile has these properties:

2013-12-29 20:10:23.081 Corona Simulator[1544:507] _proxy    userdata: 0x7fb83ebf7c28

2013-12-29 20:10:23.082 Corona Simulator[1544:507] _class    table: 0x7fb83e6ba790

2013-12-29 20:10:23.082 Corona Simulator[1544:507] tileY    18

2013-12-29 20:10:23.082 Corona Simulator[1544:507] tileX    5

2013-12-29 20:10:23.083 Corona Simulator[1544:507] props    table: 0x7fb83bd78bf0

Props looked pretty promising but seems to be empty. There doesn’t seem to be any way to add properties to tile in Tiled. There must be some way to identify the frame number of each tile. 

@tilen.curin:

Physics support (Box2D) is done by first adding physics:enabled = true. Then, any properties you want to go in the addBody physics table:

[lua]

                                Physics table

                                      |

                                      V

physics.addBody(object, {bounce = 0.5, friction = 0.1})

[/lua]

Is simply prefixed with physics:. For example, if you want your object’s density to be set, you’d use physics:density. If radius, it’d be physics:radius. BodyType is a special property; it’s not added via the physics table. Instead, you set it “outside” the call:

[lua]

physics.addBody(object, {bounce = 0.5, friction = 0.1})

object.bodyType = “static”

[/lua]

You can normally also add bodyType inside it, as the second argument, but that’s not the way Dusk does it.

As for the !json! prefix, that’s just a flag that says to Dusk, “Hey, Dusk! This property here I want you to treat as JSON notation. What follows will be a table.” That means you can create tables quite easily from within Tiled - simply prefix it with !json! and it’ll fire up the JSON parser that’s built into Corona. It’ll work equally with Lua or JSON maps.

@soggybag:

There isn’t a way to get a tile that doesn’t exist. I’ll try adding this into the next release.

The props table is for “hot” properties; those that Corona interprets as having a special meaning - x, y, alpha, xScale, etc. Adding them to the props table does nothing to the object itself. To add something to the props table, prefix it with props:. For example, props:x will evaluate to obj.props.x, and consequently not modify the position of the object.

  • Caleb

Okay…so I have 3 layers of tiles, 1st contains background tiles, 2nd are supposed to be walkable tiles (the player must not fall through them) and 3rd layer are supposed to be wall tiles (the player must not walk through them).

Can I just add properties to layers, or must I add properties to each individual tile?

I was thinking of adding properties like these to layers:

name/value

-bodyType static

-physics:enabled true

etc

would these properties apply to all tiles on the layer?

EDIT:

tried it out myself. Seems like you can add properties like physics:enabled, but you can’t set bodyType for the entire layer of tiles.

Physics properties will be added to the tiles or objects automatically. Other properties (like bodyType) must either be added to each tile (long and tedious) or be added with the prefix tiles: or objects:, for tile layers and object layers, respectively. In other words, values prefixed with tiles: are added to tiles within the layer, and objects: for objects.

So your example would translate to this:

[lua]

physics:enabled = true

tiles:bodyType = static

[/lua]

  • Caleb

Now I just gotta find out why my tiles just fall down, even though I have set their bodyType to static in the properties :/

Static bodies usually just float there, not affected by the gravity or velocity as far as I know.

Don’t know why my tiles just fall down.

EDIT:

I just noticed that whatever properties I try to add to seperate tiles won’t be applied. Nothing.

Properties that I add to layers will work, but if I add properties to seperate tiles, it won’t work.

What could be the reason for that? 

I had this problem too…and its a silly embarrassing mistake (at least mine was). If you are adding the properties or anything and nothing is working when you export it to your game, a possible solution is not in the programming but on where you export it to. Be very careful on where it says you are exporting the files to and where its reading it from, you probably have it set to your old game folder and not the correct one.

If that doesn’t fix it, maybe some other people are having this problem lol :slight_smile: