Dusk Engine

To extrude a tileset, you “pull out” the edges of each tile, then make the map tile size a bit smaller than the resulting tile. That way, you get small overlaps on each tile. I don’t know how well it works, I’ve just heard of it helping.

In previous versions of Dusk (come to think of it, all the way back to Ceramic and CoronaTiled), preferences were handled by modifying properties in the engine object itself. That’s where you’d have used “dusk.detectMapPath = true”. Now, there’s a function call, “dusk.setPreference”, that does it instead. The equivalent would be “dusk.setPreference(“detectMapPath”, true)”. You can read about preferences more if you download the API docs.

That particular option, detectMapPath, tells Dusk to check for tilesets in the same directory as the map. If you use a “maps” folder with tilesets in it, you’ll need to use this. It defaults to true, so you won’t need to change anything.

  • C

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?

Sorry if i’m missing the obvious…

When using map.setCameraFocus(player) the player is always in the center of the screen.

I want the player to x number of pixels from the left… Is it possible ? 

Ah, yea I’ve been thinking about that as well.

I haven’t been peeking at Dusk files that much, but if you go to Dusk—>dusk_core—>run , you can find a .lua file named “camera”.

That is probably where the main camera code is written.

I’ve tried reading the code there and it’s well commented, so if you take some time, you’ll understand it eventually (it’s just lua).

At line 232, you’ll see a comment " Get/ Set Viewpoint".

It looks like this:

 function map.setViewpoint(x, y) tprint.add("Set Camera Viewpoint") local x, y = getXY(x, y) camera.viewX, camera.viewY = x, y tprint.remove() end

If you want to center the camera a bit left from the player, you should change this line:

camera.viewX, camera.viewY = x -100, y

In this case I moved it 100 pixels to the left.

You can add more or less, whatever suits your game.

Same for y value.

Sorry for late reply.

This has worked for me…there may be other ways to do it, but I haven’t taken enough time to understand all the code yet.

Caleb P will know for sure.

Anyways I hope this helped…

First of all thanks for the help Tilen.

So trying to set the player to be a third into the screen, I did the following

camera.viewX, camera.viewY = x + (display.contentCenterX - (display.contentWidth / 3)), y

this caused a problem with the beginning of the level starting a third of a screen in and also the level ending to show a third of a screen extra at then end, so I modified the setCameraBounds

map.setCameraBounds({xMin = display.contentCenterX - (display.contentCenterX - (display.contentWidth / 3)),yMin = display.contentCenterY,xMax = map.data.width - display.contentCenterX - (display.contentCenterX - (display.contentWidth / 3)),yMax = map.data.height - display.contentCenterY})    

This is all well and good but surely there must be a better way to do this using one of the map methods…

Sorry for the delay in answering, I was in China :slight_smile:

Dusk actually does support non-square physics shapes, simply use the physics:shape property (as you would in normal Corona) and a JSON table prefixed with !json!.

physics:shape = !json! [0,0, 100,0, 0,100]

  • C

I am looking for a way to modify the layer/tile properties for friction.

I tried within the layer properties in Tiled t oset the friction with

layer.props:friction = 0.5

and I also tried

tiles:friction = 0.5

but none of the properties worked.

is there someone who can give a hint?

thanks sooo much in advance

Cheers,

johannes

physics:friction = 0.5
On the tile properties should work

Dont know how to do it from the layer…

That same thing’ll work for the layer, since the layer itself isn’t given physics.

  • 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 ...

Thank you so much guys - this really helps me to speed up :slight_smile:

Hi all -  I’ve created a tilemap using Tiled and I’m using the Dusk engine to display it. According to the Dusk documentation I think I need to reference objects created in Tiled using:
layer.object[name]
but I get Corona Simulator Runtime errors reporting nil values.

I’ve added a rectangular object called ‘startmarker’ and I want to use the x position of that marker to insert the player at the start of the game.

significant lines of my lua file is as follows (sorry if it’s disorganised, I’m still learning how to work with this…):
[lua]
local dusk = require(“Dusk.Dusk”)
require(“Plugins.mapcutter”)

local map = dusk.buildMapFromLayers(“map.lua”, {3,3})
map.x = display.contentCenterX - (display.actualContentWidth/2)
map.width = display.actualContentWidth * 3
map.y = display.contentCenterY - (display.actualContentHeight/2)
map.height = 265

map.layer[“markers”]:insert(startmarker)
local startmarker = map.layer.object[“startmarker”] <-- tried these two lines to help identify ‘startmarker’ object within the map layer but it doesn’t seem to help

map:scale(1, 1)
map.updateView()
map.setTrackingLevel(0.3)

local sheetData = { width=40, height=40, numFrames=12, sheetContentWidth=480, sheetContentHeight=40 }
local mySheet = graphics.newImageSheet( “boss.png”, sheetData )

local startmarker = mySheet.layer.object[“startmarker”] <-- tried this too but it’s not working

local t = 1000;
local sequenceData = {
{ name=“boss”, start=1, count=12, time=t, loopCount = 0 },
}

local boss = display.newSprite( mySheet, sequenceData )
boss.myName = “boss”

boss.x = -30;
boss.y = 165
boss.xScale= 3.5
boss.yScale= 3.5
boss:setSequence( “run” )
boss:play()
transition.to( boss, { time=6000, alpha=1, x = startmarker.x }) <-- I want the destination of the transition.to to be the x value of the Tiled rectangle object
[/lua]

I’d be really grateful if you could offer me any advice, I seem to be getting nowhere…

Many thanks

map.layer holds map layers, so you need to identify a layer to access with map.layer[x].object[“startmarker”].

Hope it helps :slight_smile:

  • C

Thanks Caleb. So, the object layer in Tiled is called ‘markers’, so I’ve entered the following:

[lua]

transition.to( boss, { time=6000, alpha=1, x = map.layer[“markers”].object[“startmarker”].x }

[/lua]

I’m not getting any success and when I use the above in line 28 and comment out lines 8, 9 and 15, I get:

'Attempt to index field ‘markers’ (a nil value)

Do I need to declare something earlier?

Thanks a lot for your help.

– edit  – I’ve been playing around with different local declarations at the beginning of the file but without any luck. I found another thread that mentions inserting the character into the map layer, which seems logical but that doesn’t fix it…

Are you sure you’re not “cutting” out the layer with MapCutter?

  • C

I don’t think I’m cutting the layer…?

I’m using composer (probably not very well) and here’s the file in which I’d like to reference the position of an object from Tiled to use as a positioning reference for the game character:

[lua]

local composer = require( “composer” )

local scene = composer.newScene()

local mydata = require( “mydata” )

local physics = require( “physics” )

physics.start( )

local gameStarted = false

display.setStatusBar(display.HiddenStatusBar)

local textureFilter = “nearest”

display.setDefault(“minTextureFilter”, textureFilter)

display.setDefault(“magTextureFilter”, textureFilter)

local topY = display.screenOriginY

local rightX = display.contentWidth - display.screenOriginX

local bottomY = display.contentHeight - display.screenOriginY

local leftX = display.screenOriginX

local dusk = require(“Dusk.Dusk”)

require(“Plugins.mapcutter”)

local map = dusk.buildMapFromLayers(“level.lua”, {3,3})

map.x = display.contentCenterX - (display.actualContentWidth/2)

map.width = display.actualContentWidth * 3

map.y = display.contentCenterY  - (display.actualContentHeight/2)

map.height = 265

map:scale(1, 1)

map.updateView()

map.setTrackingLevel(0.3)

local sheetData = { width=40, height=40, numFrames=12, sheetContentWidth=480, sheetContentHeight=40 }

local mySheet = graphics.newImageSheet( “character.png”, sheetData )

local sequenceData = { 

   { name=“characterrun”, start=1, count=12, time=1000, loopCount = 0 },

}

local character = display.newSprite( mySheet, sequenceData )

character.myName = “character”

character.x = -30;

character.y = 165

character.xScale= 3.5

character.yScale= 3.5

character:setSequence( “characterrun” )

character:play()

transition.to( character, { time=6000, alpha=1, x = 500 })

return scene

[/lua]

In line 49 I’d like to replace ‘x = 500’ with ‘x = x position of object made in Tiled

What would you type there to reference that?

I realise I’m not identifying a layer as per your previous post - I couldn’t get that to work. I kept getting nil value errors however I tried… perhaps you could give an example?

The layer in Tiled with the objects is called ‘markers’ and the object within that layer I’d like to reference is called ‘startmarker’.

Thanks for your help, it’s really appreciated - I’m not a programmer so it’s not obvious to me how to implement this but I’m sure once I’ve got this I’ll be able to apply it elsewhere in the project…

Many thanks

You should just be able to do something like

for object in map.layer["markers"].nameIs("startmarker") do character.x = object.x end &nbsp;

Maybe Dusk is not compatible with composer…

I have something like

&nbsp; &nbsp; local screenGroup = self.view &nbsp; &nbsp; map = dusk.buildMap("levels/level"..selectedLevel..".json") &nbsp; &nbsp; screenGroup:insert(map) &nbsp;

and startmarkers / spawnpoints are working ok…