Dusk Engine

The video tutorial is outdated; Dusk now supplies iterators to get multiple objects with the same name from your map, or just an ‘object’ table to get a single object.

To get a single object:

[lua]

local crate = map.layer[“object layer”].object[“crate1”]

[/lua]

To use an iterator:

[lua]

for crate in map.layer[“object layer”].nameIs(“crate”) do

  – Do something to each crate

end

[/lua]

Of course, you’d replace “object layer” with the name or index of your layer.

  • C

Thank you Caleb,

   Much help. Also, is it possible to add an event listener (addEventListener) to a tile layer or to the individual tiles themselves? I have been able to do this to objects in the object layer, but not the tiles in the tile layer. I suspect I could do it to whatever the variable for my loaded TiledMap is, but I’m not sure.

Dusk maps, layers, tiles, and objects are just normal Corona objects. The map object and layer objects are groups, tiles are sprites, and objects are either vector objects or images, depending on the type. Thus, to add a listener:

[lua]

map:addEventListener(“listenerName”, listener)

map.layer[1]:addEventListener(“listenerName”, listener)

map.layer[1].object[“crate1”]:addEventListener(“listenerName”, listener)

map.layer[2].tile(5, 5):addEventListener(“listenerName”, listener)

[/lua]

Note that you might need to lock a tile from being culled if you add a listener to it, or it will get deleted.

  • C

Good idea; I’ll add that when I can.

  • C

I see the github page says “open source” but what’s the license for Dusk?

 Jay

I haven’t thought of this before, but I guess it’d be MIT.

I’ll add it to the GitHub repository.

  • C

Awesome, thanks!

 Jay

Caleb is it possible to do curved tiles?

What do you mean by “curved”? The physics shape?

  • C

curved as in many edges to the tile to give a curved appearance.

i figured it out just gotta set the physics shape in the tiled properties…

physics:shape = !json! [35,34,-35,35,35,-34] 

cheers caleb

I too was facing the same problem initially and solved it with adding a physics:shape property in Tiled. This process was extremely time consuming. Any idea if it is possible to do this graphically?

You can try adding two physics shapes to the tile; one with a radius, and one shape filling the rest of the tile:
 
(assuming 32x32 tiles)
[lua]
physics:radius     :     16
physics2:shape : !json! [16,-16, 16,16, -16,16, -16,0, 0,-16]
[/lua]

Basically what that does is uses Dusk’s multiple-body-parameter feature to create two physics sections of the tiles, just like you can do with normal Corona physics:

[lua]
physics.addBody(tile, “static”,
{radius = 16, bounce = bounce, friction = friction},
{shape = {16,-16, 16,16, -16,16, -16,0, 0,-16}, bounce = bounce, friction = friction}
)
[/lua]
One is a 16-radius circle, to form the curve part, and one is a sort of diamond shape that blocks off the other three corners of the curve.

  • C

Caleb and/or anybody in the know:

I like the camera system however I have a couple of questions:

  1. I notice that when I set the focus to an object (say to the player) the camera locks onto the tracked object so that it always appears in the centre of the screen. Is there a setting within the engine that allows me to have this set to a different offset on either the X or Y?

  2. Because of the way it tracks the focus object, when the object gets close to the edge of the map the map will scroll offscreen, is there a setting that prevents the map from doing this so that when near the edges of the map the ‘camera stops moving’ and it would appear the focus object moves instead (until it gets away from the map edges in which case the tracking goes on as per normal)? 

hope that makes sense

  1. Yes; I might add an easier way to do it to multiple layers, but for now it’s

[lua]

map.layer[x].setCameraOffset(x, y)

[/lua]

Don’t use the map.layer[x].setOffset(x, y), I deprecated it just now because I realized it’s not clear what offset you’re setting :slight_smile:

  1. You’re looking for map.setCameraBounds().

[lua]

map.setCameraBounds({

  xMin = [the minimum X the focus has to be for the camera to track it],

  yMin = [the minimum Y],

  xMax = [the maximum X the focus can be for the camera to track it],

  yMax = [the maximum Y]

})

[/lua]

  • Caleb

thank you very much Caleb!

caleb, nice work on dusk… cannot get rid of the gaps between the tiles in bob… tried config settings, settting default to nearest but still same problem… n e idea how to fix accross devices?

if anyone else wants to fix the gap issue just use texturepacker and set extrude>0 or just use toad which caleb includes with dusk.

Hi, I have a problem, Im doing Coins in my game, and I create Coins in Tiled Map Editor, with physics, and when have collision with some coin, this coin is removed.

The problem is when I have more coins, with same name “coins” to the objects, not found. 

I have this code:

[lua]

local coin =  map.layer[“LayerCoins”].object[“coin”];

moneda.myName = “Coin”

local function onCollision( event )

if ( event.phase == “began” ) then

   

if ( event.object2 == coin or event.object1 == coin ) then

print( “Bost” )

bost = bost + 1

textBost.text = bost

coin:removeSelf()

end

end

end

Runtime:addEventListener( “collision”, onCollision )

[/lua]

Some idea for select all objects of one layer, or what can i do it?

regards, thx!

this is what i do and it works…
iterate through each object. for each object named “coins” add addEventListener( “collision”,coinCollision())

for object in map.layer[“objects”].objects() do

if object.name == “coins” then

addeventlistenere here

end

end

Im trying but not found, I do:

[lua]

function coinCollision( event )

    if ( event.phase == “began” ) then

print( “Bost” )

bost = bost + 1

textBost.text = bost

coin:removeSelf()

   

end

end

for object in map.layer[“LayerCoins”].objects() do

if object.name == “coin” then

Runtime:addEventListener( “collision”, coinCollision() )

end

end

[/lua]

But not found, i do too the function coinCollision() in the FOR, but nothing…

thx!