Dusk Engine

Just pushed a cool new “dev tag” (my new name for pre-1.0 releases) to GitHub. Read the tag information at https://github.com/GymbylCoding/Dusk-Engine/blob/master/LATEST_TAG_NOTES.md for full information.

Anyhow, the coolest thing in the update (IMO) is the new edge mode feature. You can set a tile layer’s “edgeModeX” or “edgeModeY” properties to control how the tile layer’s culling/drawing is done. To make tiles in a layer wrap around in the X-axis when the culling reaches the edge, you set “edgeModeX” to “wrap”. A value of “clamp” will clamp to the farthest tile in either dimension, and “stop” (the default) will stop drawing when it reaches the edge.

  • Caleb

The tileset I’m using has 64x64 tiles, with a spacing of 8 pixels between each of them. There is also a gap of 8 pixels between them and the edge of the page.

I just tried using a tileset with no margins or spacing, and that worked fine.

Hi Caleb,

I have been having some issues trying to add physics to my tilemap.

I followed the documentation and added the properties physics:enabled = true and tiles:bodyType = static to a layer, but when I load it in my scene all the tiles in the layer disappear.

I looked at the example projects, and some of my other Dusk projects, and I can’t see what I am doing wrong.

Does your tileset fit correctly with the dimensions? That is, is 8+8+(64*num columns)+(8*(num columns - 1)) = the width of your tileset and the same for height? Sometimes Tiled loads a tileset fine when dimensions are wrong but I’m not so sure about Dusk…

If everything looks good, can you PM me your map file so that I can take a better look?

As for physics, try doing this and see if it still happens.

  1. Make a new map with your tile size, and load your tileset in it.

  2. Draw tiles in your map, blah blah blah

  3. Set physics:enabled and tiles:bodyType in the layer properties

  4. Load in project

What you’re doing here is just making the most basic map you can. I just did the same thing and it worked fine for me (programmer’s worst nightmare :)). If it’s still not for you, make sure you have the most recent version of Dusk and post again.

  • Caleb

What is the best way to implement parallax scrolling with the Dusk Engine?
I’ve spent the last week running test maps through Dusk in an attempt to get a fluid parallax effect. It’s working, but is far from fluid. I’m posting from mobile so I don’t have my code handy, will post that later. Here’s how it works, or doesn’t work ;).
1.) Build the map.
2.) Define individual layers.
3.) Create sprite with simple animation. Define linear velocity.
4.) Insert sprite into a platform layer (physic set up…works fine).
5.) Lock camera to sprite(centerX)
6.) Create functions to update x position of each layer(islandlayer.x = islandlayer.x - 5). Each function ends with map.updateView ().
7.) Run each function with timer delay:
timer.performWithDelay (1, updateIslandLayer, -1)

Like I said, this system does work, the layers scroll at different speeds. There are serious performance issues though. Within a few seconds, my sprite slows to a crawl. I’ve narrowed the problem down to the culling system. If I turn culling off (not really an option…map is 64000 pixels wide), there is no noticeable slowdown over time. There is still a performance issue because I’m loading a very large map into memory all at once.

My questions
Is there a better way to implement parallax?
Is there a way to have partial culling? Load entire map…remove tiles as they pass off the screen?

So sorry you spent so long on this; I really need to write docs :(.

Parallax scrolling is already implemented. Just set a layer’s xParallax and yParallax properties (from layer properties or programmatically), and the camera system will move each layer accordingly and cull correctly. Parallax is 1 -> normal, 0.5 -> half movement, 2 -> twice as much movement, etc.

  • Caleb

LOL, no worries Caleb. You rock. The parallax works great. Thanks for all your hard work. 

Hello, everyone!

If you haven’t already done so, please (please, please, please!) take the Dusk survey I made. I really need your feedback. You can find it here: http://goo.gl/forms/N1SVTCNAJa . This is seriously very important. Thanks!

The forum post is here: https://forums.coronalabs.com/topic/54887-dusk-engine-survey/

  • Caleb

I have a question related to accessing tiles by screen coordinates. I have created a simple map 8 x 8 tiles, with two layers. When you click on a tile in the toplayer, it removes the tile and reveals what’s underneath in the bottom layer. If I load the map without changing the camera position or viewpoint, the touch function works great. I really want the map in the center of the screen though. As soon as I alter the camera position and viewpoint, the touch listener no longer works. Tapping on a tile removes a different tile. I know what’s going on, and I know I can fix it mathematically, but wondered if there was a simpler “dusk” way to handle this. Essentially, when the map is loaded at (0,0), using map.layer.tilesByPixels(x,y) works great because the x/y coordinates of the map match up with the x/y coordinates of the screen. However, as soon as I move the map, they no longer match up, so when I touch the screen at 524,524, it removes the bottom right tile of the map, which is the map pixel coordinate 524,524. Here’s my code:

local dusk = require("Dusk.Dusk") display.setDefault("minTextureFilter", "nearest") display.setDefault("magTextureFilter", "nearest") local centerX = display.contentCenterX local centerY = display.contentCenterY local map = dusk.buildMap("map001.json") local toplayer = map.layer["toplayer"] map.setCameraBounds({xMin = centerX, yMin = centerY, xMax = map.data.width - centerX, yMax = map.data.height - centerY}) map.positionCamera(map.data.width/2, map.data.height/2) map.setViewpoint(map.data.width/2 , map.data.height/2) local function touchTile(event) local t = event print(t.x, t.y) local tile = toplayer.tileByPixels(t.x, t.y) display.remove(tile) tile = nil return true end local function updateMap() map.updateView() end timer.performWithDelay(1,updateMap,-1) toplayer:addEventListener( "touch", touchTile )

There isn’t a built-in Dusk way for this, but it’s really easy to do:

local layerX, layerY = toplayer:contentToLocal(event.x, event.y) local tile = toplayer.tileByPixels(layerX, layerY)
  • Caleb

Exactly what I needed. Thanks Caleb.

Hello, all who are notified from this topic!

I’d appreciate it if you’d take my Dusk survey I created. The forum topic is http://forums.coronalabs.com/topic/54887-dusk-engine-survey/.

The survey can be found at http://goo.gl/forms/1JjsBp9DB7.

Thank you!

  • Caleb

Hi Caleb,

is it possible to animate image sheet frames (tiles) when they are located over the whole image sheet by using their index?

Right now animations are something like “from image (tile) 1 to 4”… but I need something like {1,2,2,16,13,13,10,5}

Is this possible already?

  • Daniela

Just posting to tell everyone about the really cool new features I’ve added to the dev branch of Dusk: OBJECT CULLING! FINALLY! Besides that, I’ve also added tile state listeners (“Hey Dusk! Tell me when this tile gets drawn, ok?”) and tile data construction (“I know this tile doesn’t exist yet, but can you generate the data it would have if it did exist?”).

These new features are alpha-quality, so they’re in the dev branch on GitHub. Please download it and see if everything works for you. If you find any bugs, post away! Also, be aware that some things might not be fully complete (i.e. there’s currently no way to stop objects from being culled apart from a map-wide Dusk preference, and all objects are culled, even data objects, etc.).

  • Caleb

maschietto.jr:

Sorry to ask this, but i searched for the entire forum before.

Whats is the properties i need to set on an object, tile, or layers to make then a body. They dont colide with my sprite. I was using lime and was working.

I found the properties objects:bodyType and tile:… here in forum. But i think is missing something or i am using wrong. Where do i use this properties? Is on Properties on Tiled right?

Caleb P:

This is actually the original old post… The new one is http://forums.coronalabs.com/topic/42355-dusk-engine/. If you’ll post there instead, that would be good.

However, to answer your question, the properties you’re looking for are the physics: properties. You can make a single object or tile physical by adding physics:enabled = true to your object or tile properties, or the entire layer physical with physics:enabled = true as a property on the layer. Each parameter you need to add to the physics options (bounce, density, etc.) are all just the name prefixed with physics: - physics:bounce, physics:density, etc.

I think I have something about this in the docs; just open docs/index.html (from the main Dusk project folder) up in your browser and go to FAQ.

  • Caleb

Now in the right topic.

Thanks, it’s worked.

I do not cheked the FAQ section, sorry.

But there is something wrong when I build the map.

  1. First the objects aren’t being drawned on the right position. They appear more on the right and lower than they really are on tiled.
  2. The second thing is the colission detection. In “hybrid” mode i can see the collisions area in the right place. But it reallys occur a tile before. For example: In a platform, the first tile has no collision ( but in hybrid mode i can see te box ). And there is ghost tile ( with no box on hybrid mode ) thats has colission.

I uploaded a printscreen.

I have some questions regarding the creation of a side scroller with dusk:

  1. how can I use different tile sizes for different layers of one level? Like for example: big background image blocks (like 512x512px image files) for the scene background (mountains etc.) or even bigger images, midground images in another resolution and foreground tiles, like 64x64px tiles for platforms etc.

  2. Is there an existing sample for a sidescroller available somewhere?

  3. How do I manage the different speeds of layers?

  4. What are the camera options I have for such a game and how can I use them? (follow player, zoom in, zoom out, easing cam…)

Thank you for your help Caleb!

I asked this in other topic so sorry for double post, but maybe someone here could help 'cause there are more readers in this topic.

Following demo is made with Dusk and Box2D. I’ve read some problems that may occur with physics in tile based games. Please check this 10 sec video:

https://www.youtube.com/watch?v=nOyZUYQF9lQ

When time is about 7 secs you’ll see that the character “hits” the unvisible wall (tile seem?), though the character is on solid ground the whole time. Is this typical problem with tile engine games that are using Box2D physics? And if it is, how can I fix this?

Unfortunately, that is a very common problem with physics engines and tiles. It can’t be completely “got through” (unless you use a custom physics approach), but a number of workarounds exist:

  • Make the player’s body a shape with clipped off corners at the bottom

  • Make the player’s physics body circular

  • Make the player a multi-element physics body with a circle at the bottom

  • Give the player a tiny bit of bounce

  • Give tiles a clipped-off-corner shape and the player a normal rectangular one with a bit of bounce

  • Caleb

Also, @d.mach:

You can do that through the anim:options table. Possibly a more user-friendly way will come sometime, but right now just provide a ‘frames’ table just like in a normal Corona sprite.

anim:options = !!! frames: {1, 2, 3, 4, 5, 4, 3, 1, 9, 2} time: 1000
  • Caleb