Dusk Engine

Hi, Forgive my noob-ness for what I’m about to ask… Can anyone help me to further understand GID errors that Corona simulator throws out when trying to run my maps? Is there something I’m missing when it comes to setting up tilesets in tiled? I have yet to get a map to load and have tried to figure out what I could be doing wrong to no avail. I’ve been using Corona for years, but never really messed with tile engines much. I used Lime a bit and things worked out just fine, but of course we all know that that takes a bit of work to use nowadays and Dusk seems so much easier.

@guillaume.aujay:

This is tile culling at work. You can either turn culling completely off (thereby slowing down Dusk for large maps), or you can move the map and call .updateView(), or you can use the “core-ish” layer._constructTileData() function. Turning culling off is as simple as this (before building your map):

dusk.setPreference("enableTileCulling", false)

updateView() is the function which controls tile culling and keeping tiles in view:

-- In your enterFrame listener or somewhere like that: map.updateView()

_constructTileData() gives you the tile data for a tile, regardless of whether it’s drawn or not. It has an underscore in front of it because that’s my coding practice for less “sleek-and-simple-and-friendly” functions. It’s fairly slow, so don’t use it like you might use layer.tile() - instead, create a variable to hold the data when you build it.

local tileData = map.layer[1].\_constructTileData(xOffTheScreenSomewhere, yOffTheScreenSomewhere)

Tile data constructed with _constructTileData will have most fields normal tiles will have.

@c.noeth:

I don’t have the code off the top of my head, but if you have any issues, you’re welcome to post if you run into snags. What are your problems figuring it out?

@beanmachine1987:

What errors are you getting specifically? Something like “Invalid GID at position [x,y]”?

  • Caleb

Hi Caleb…before anything, many thanks for your work!!!

Perhaps the problem that @beanmachine1987 is talking is related to Tiled version.

When I use 0.13.0 (the most recent version) the GID error appears. So now I’m using 0.12.3 and everything is ok.

Best regards,

Erich Grüttner D.

Hm… I just downloaded 0.13.0, and everything’s working for me out of the box.

I am able to get a GID error if I set “Tile Layer Format” in the properties window to one of the compressed options or Base64 uncompressed, so make sure that’s either XML or CSV.

  • Caleb

Thanks for tip! I’ll give this a try.

Joey

I feel like an idiot, I’m almost positive that all my maps have been Base64… I didn’t know otherwise and had started messing around with this while being half asleep. Logic kinda goes out the window at that point. :stuck_out_tongue:

Caleb, as for the exact error I was getting… 

Thanks for the quick replies and your awesome work. It’s very much appreciated. 

@caleb You were right. It was the the tile layer format. Everything is smooth now.  :D Thank you!

Hello @Luiz.pablo.lopez. I guess you could scale down your map after you’ve created it. So, after the code that creates the map you code this:

map:scale(0.5, 0.5)--scales down the map map.updateView()--update the view of the map

You have to call the updateView function, so the map can scale after it has been created.

If you want it to get bigger, use values bigger than 1, else then you use lower values than 1, for example: 0.5.

Hope it is what you are looking for.

I’ll add to @carlos.rafael’s answer with this: If you want to fit the map into the screen, just use some basic algebra:

-- Calculate the scale the map needs to be to fit into the screen local mapScaleX, mapScaleY = display.contentWidth / map.data.width, display.contentHeight / map.data.height -- ...and scale the map map:scale(mapScaleX, mapScaleY)
  • Caleb

Please note for future reference: I am going to completely stop answering questions on this topic. If you need help, please create a new topic in the “Gymbyl Coding” subforum.

  • Caleb

Caleb, would you like me to lock this thread?

Rob

I’m having difficulties positioning my map, i’m a newbie.

I want my map to start from the bottom left not in the middle.
I tried setCameraBounds but it just wont work.

What i did is tried setViewpoint and it somehow works but it messes up my tiles.

Any help will be appreciated.

Thanks

Hi Caleb!

I am struggling with the object iteration when I am using the Dusk’s dev branch.

This is what I am trying to do:

[lua]

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

            local table = {}

              if not (doesTypeExist(table,object._type)) then – doesTypeExist() checks if the object’s listener is already made by checking the table content

                addObjectType(require “objects.” … object._type)

                table[#table+1] = object._type

            end

        end

[/lua]

The loop [lua] for object in map.layer[“Objects”].objects() [/lua] finds only displayed objects and as the code above shows I want to add all objectTypes from the map.

EDIT: Sorry for the rough code editing I had to do from the 1st time I posted this. Really need to read my posts before I send :smiley:

Hi,

Im having a strange issue. Im building a platformer game and i position my map in the bottom left of the screen like this 

local map = dusk.buildMap("levels/level1.json") map.y = -map.data.height + display.contentHeight

I have a ground layer with physics:enabled and tiles:bodyType static.

When i insert my character to the ground layer it appears above the screen then falls down and collides

with the ground.

physics.addBody(character, "dynamic", { friction = 0.0, density=1.0, bounce = 0.0}) map.layer.Ground:insert(character)

What i want is my character to be positioned in the center of the screen, i tried 

character.x = display.contentCenterX character.y = display.contentCenterY

it works if i don’t insert the character to the ground layer, but when i insert it it just positions above the screen.

  • Best

@yaliyaa:

I’ll need some more information. What do you mean by “start at the bottom left”? Do you want to position the camera at the bottom left of the map?  How did setViewpoint mess up your tiles?

@Painconfess:

You can either turn object culling off, or iterate through the objects’ data (there’s an iterator for that with the latest branch), but a better way is probably to add every object type in your code. What I have is each object type (just like yours, stored under objects/objectType.lua), then I have a types file that looks like this:

return { require("objects.cupcake"), require("objects.explodingCow"), require("objects.poisonedAcorn"), require("objects.wonkaBar") }

Then, in my code, I iterate through the object types file and add each object type from it. If you want to only load the object types you need, the iterator is ‘objectDatas’. It iterates through each object data stored in the layer. The object data is in a special format, so you might need to explore the format with a few pairs() loops to see how things are stored. Basically, there’s some object building data in the table, then a ‘transfer’ table that contains stuff the built object gets. The _type will be in the ‘transfer’ table.

for objectData in map.layer["objects"].objectDatas() do print(objectData.transfer.\_type) end

@yaliyaa #2:

This is a mix-up between local and content coordinates. Insert the player into the layer, then you should be able to fix this with Corona’s contentToLocal function:

player.x, player.y = map.layer.Ground:contentToLocal(display.contentCenterX, display.contentCenterY)
  • Caleb

Hi Caleb,

Yes i want to position my camera at the bottom left.
I’m building a sidescroller game.

That would be great, thanks.

  • Caleb

You can set a layer’s camera offset via layer.setCameraOffset(x, y). That might be what you’re looking for. Otherwise, can you give me an example of what you mean?

  • Caleb

If I use collision filtering for my player and bullets the player fires-- the tiles will not be part of any collision detection between them. How do I add a collision filter to the tiles? Or can I?