Dusk Engine

In fact, I’m using image object for decoration in my map. I basically create a tileset per image (because they are at different size) where the tile width and height are the one of the image, so that turns into 1 tile and then add them as image object in the map. I don’t see another way for adding different sized images to Tiled, so maybe someone knows a better way  :slight_smile:

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!

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.

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?

You can use Dusk’s JSON or Bang (I recommend Bang!) notation to do that (in tile properties):

physics:filter = !!! categoryBits: 4 maskBits: 1

You can use one of the collision filter helper charts (one is on the docs page at https://docs.coronalabs.com/daily/guide/physics/collisionDetection/index.html) to find the correct values for tiles to collide.

  • Caleb

Okay I got this far but how do you use Bang notation to change the physics:filter of each tile?

for tile in map.layer["tiles"].tilesInRange(1, 1, 32, 32) do            if(tile.bodyType and tile.bodyType == "static" ) then             --physics:filter     =     !!! categoryBits: 4 maskBits: 1 ?????         end end​

Also, how do you return  how many tiles are in the map? When I iterate through this code it seems I have 832 tiles in the map. But its a 32x32 map size. Shouldn’t the map tiles size be 1024? Am I using “tilesInRange” wrong??

The dusk engine is awsome everthing worked perfect unti added the code for the Player  to fire bullets. There was collision between the player and the bullts ugh.

Thanks for all your help Caleb

Hi Caleb and thank you from the earlier response of my previous problem! :slight_smile:

But once again there is something I need your help.

I want to achieve the same thing Aatos Media wanted awhile ago:

So the question is: where do I add the nil check? I have tried right before the error and in the beginning of the addObjectType function and many other places, but then occurs more dusk_core errors.

@burnsj002:

The filter notation will go in the tile properties from Tiled. With the most recent version of Tiled (0.13.0 at the time of this writing), click on the tile you want to have a filter, then add a property from the properties menu.

@Painconfess:

The nil check’ll be in the object type building code. After you create your object via the params.build function, check for if the object was created. If it was, proceed, otherwise, cancel and clean up or whatever. Then, add another nil check in the object type removal code erase listener.

  • Caleb