Dusk Engine

Hi! I’m with a team working on a platformer game using the Dusk engine, and we’re trying to make stairs that you can jump on top of and walk in front of. Is there a way to turn physics on and off for either an entire layer or for a group of tiles?

Whew! It’s been a long delay, because of the hectic-ness surrounding the release of my first game, so I’ve just begun on refreshing all the libraries that have been neglected :slight_smile:

I can’t give a release for Dusk right now, but I figured people might just enjoy seeing this screenshot (attached) of a tool developed for it.

And yes, it does have the very official-sounding name of “TOAD” :smiley:

  • C

awesome Caleb! ill buy your game for sure :smiley:

14? wow!

Caleb P., or anyone who can answer this,

I am trying to reference an object that I created in Tiled in my main.lua file. In Tiled, I named my object “crate1”. How do I reference crate1 in my main.lua file? In Michael Wilson’s video on using Tiled, he said in order to do this, I could type “crate1 = tiled:findObjects(“myCrate”,map.data)”. That obviously doesn’t work anymore. Please assist. Thank you.

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

@CSIV2013to2014

Sorry for late answer.

Uhm…I wouldn’t recommend playing around with physics during collisions. Adding physics bodies, turning physics on/ off and all that can ruin the performance of your game. 

I’m not sure if it’s possible to do that…right now I can’t think of anything to access layer properties within main.lua

Correct me if I’m wrong please.

You could however detect if your character (or something) collides with tiles, and it’s possible to detect if physics bodies collided vertically or horizontally.

If they collide horizontally (while moving over the X axis), let the character pass through the stairs. How to let him pass through the stairs?

I think it’s possible to do that by using collision—>event.contact

Haven’t tried using event.contact myself yet, but that’s probably what we’re looking for.

…yeah, they use event.contact for the same thing right here.

Ok, so how to detect if objects collide vertically or horiontally?

I came up with some code that can detect that…originally I used it for something in my game.

Anyways here’s the code:

--detects if the character hits a wall by its side or its top. function colision\_detect(event) if(event.object1.myName == "tile" and event.object2.myName == "character") then if(event.phase == "began") then if(event.object2.contentBounds.yMax \> event.object1.contentBounds.yMin) then print("collided horizontally") else print("collided vertically") end end end end Runtime:addEventListener("collision", collision\_detect)

It’s basically comparing character’s y value when collision happens.

The code that I wrote there only detects if collision happened on top of the tile or on side.

Doesn’t work if they collide on the bottom side of the tile.

You could use the same method to detect if the character hits the stairs with his head, so that he can pass through them from below.

…or IF they collide on top, let the character stand on the stairs ELSE make him pass through.

You will have to make some exceptions, if the character is already on the stairs…shouldn’t be a problem.

Hope this helps.

That’s perfect!

Thank you so much!

Glad I could help!  :slight_smile:

Here’s a snippet of what I worked out for layer-specific physics:

local sprite = --instantiated sprite:addEventListener("preCollision", level.spritePreCollision); function level.spritePreCollision(event)     local sprite = event.target     local other = event.other     if(other.layer and (other.layer.name ~= sprite.layer)) then         event.contact.isEnabled = false; --disables this particular collision   end end

I had to edit the core of Dusk:

--tilelayer.lua function tilelayer.createLayer(mapData, data, dataIndex, tileIndex, imageSheets, imageSheetConfig, tileProperties) local props = getProperties(data.properties or {}, "tiles", true) local layerName = "Layer #" .. dataIndex .. " - \"" .. data.name .. "\"" ... function layer.\_drawTile(x, y) ... if layer.tile(x, y) == nil then ... local tile = display\_newSprite(imageSheets[sheetIndex], imageSheetConfig[sheetIndex]) ... tile.GID = gid tile.tilesetGID = tileGID tile.tileset = sheetIndex --I ADDED THESE FOUR LINES tile.layer = {} --or tile.layer = layer tile.layer.name = data.name; tile.layer.id = dataIndex; tile.layer.index = dataIndex; --END CORE EDIT if flippedX then tile.xScale = -tile.xScale end if flippedY then tile.yScale = -tile.yScale end ...

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.

@Caleb P

Let me suggest a feature the will make camera handling much easier to configure for the end user when it comes to setCameraBounds(). Let users configure the bounds manually (like it is now) or let them use an “automatic” mode. By this I mean, Dusk already knows the maps width and height and already knows the player position. It would be great if you could just tell Dusk to track the user with a certain amount of “padding”. This padding would be the amount of points from the edge of the map inwards that Dusk should internally set the camera bounds to so that you prevent the camera to track the user all the way to the edge of the map. In essence Dusk would be internally be just setting the camera bounds but doing some math like “mapbounds minus padding”.

It only saves the user from doing a bit of math, but I think it goes with the “easy to configure/use” Dusk motto. Plus, user code would look cleaner without this calculation.

Anyways, great job! I’m starting to use it and found it great!

Whew! It’s been a long delay, because of the hectic-ness surrounding the release of my first game, so I’ve just begun on refreshing all the libraries that have been neglected :slight_smile:

I can’t give a release for Dusk right now, but I figured people might just enjoy seeing this screenshot (attached) of a tool developed for it.

And yes, it does have the very official-sounding name of “TOAD” :smiley:

  • C

awesome Caleb! ill buy your game for sure :smiley:

14? wow!

Caleb P., or anyone who can answer this,

I am trying to reference an object that I created in Tiled in my main.lua file. In Tiled, I named my object “crate1”. How do I reference crate1 in my main.lua file? In Michael Wilson’s video on using Tiled, he said in order to do this, I could type “crate1 = tiled:findObjects(“myCrate”,map.data)”. That obviously doesn’t work anymore. Please assist. Thank you.