Dusk Engine

Thanks Caleb,

I have another question. I’m loading different maps at different points as you suggested. After I delete the old map and call the new one, I get a camera.lua error on line 96 or 100. My code is like so:

Map:removeSelf()
Map=nil
Map=dusk.buidMap…

I think it’s the “removeSelf()” that’s causing the issue because it works fine without it.

The correct way to delete a map is with the .destroy() method:

map.destroy() map = nil [...]
  • Caleb

Hello,

Whenever I’m adding the line

local map = dusk.buildMap("levels/level.json")

Im getting an error

?:0: attempt to index field ‘?’ (a nil value)
stack traceback:

        ?: in function ‘gotoScene’
       main.lua:2: in main chunk

Do you want to relaunch the project ?

main.lua contains :

local composer = require( "composer" ) composer.gotoScene( "game" )

It all works fine without including my level with the dusk engine.

My file structure is like this:
 

Dusk (folder)

–dusk_core (folder)
–Dusk.lua
images (folder)
levels (folder)

–level.json
sound (folder)
build.settings
config.lua
game_credits.lua
game.lua

main.lua

menu.lua

I have searched all over the internet to figure out why its not working, the map I have made is made in Tiled and exported as Json file.

Can someone push me in the right direction to make my map showing up at least ? thanks :slight_smile:

I still can’t figure out how to add sprite frames (with setFrame) to tiles which are not on the visible screen, so that they stay in this frame. Somehow the offscreen sprite tiles show another frame when I move the map and this sprite tiles move in the visible area.

What am I missing here?

@eschwinm:

You’re trying to use something that’s nil. Make sure that all identifiers you’re using have been created correctly, and that they’re in scope when you use them. Try out this “least common denominator” code:

local composer = require("composer") local scene = composer.newScene() local dusk = require("Dusk.Dusk") local map -- Initialize scene function scene:create(event) map = dusk.buildMap("levels/level.json") end scene:addEventListener("create") return scene

Once that works, slowly add in the rest of your code.

If, however, that doesn’t work, I’ll need you to PM me your tile map (no tilesets needed, just the map - you might be using some new features of Tiled that Dusk doesn’t support yet).

@d.mach:

You’re not missing anything - I think that’s because of Dusk culling your non-auto-animated tiles. Whenever a tile is created that isn’t auto-animation-synced, it’s set to the first frame. I just pushed a commit that saves the current frame of non-synced tiles, so see if that changes anything.

  • Caleb

Could anyone lend a hand with the following: I’d like to be able to zoom out to keep two objects visible as they move apart, and then zoom in again when the same two objects become closer. I thought I could use map.setcamerabounds for this, but my experimentation isn’t bearing fruit - any advice? Many thanks.


OK, so I thought I could get the camera to ‘zoom out’ to keep both objects in frame, but I think the way forward is to reduce the scale of the layer with something like:

[lua]

map.layer[1]:scale(1 - zoom, 1 - zoom)

[/lua]

…within the enterframe function

I’m still tinkering and I’ll post my code later in case it helps anyone, and in case anyone could suggest improvements…

One question: When using

map.layer[1].\_lockTileDrawn(55, 3)

to lock a tile. How can this tile be unlocked, so it is culled again? unlockTileDrawn?

@newbie1001:

Just calculate the distance between your objects, find what percentage of the layer’s width/height that is, and scale the map proportionately. Just two notes -

  1. Currently, Dusk only supports map-wide scale along with the camera movement. In other words, map:scale(), not map.layer[1]:scale().

  2. To keep the camera in the right place, you can average their positions and set that as the focus point. Or make a focus object that moves to the average of their position.

@d.mach:

[lua]

map.layer[1]._unlockTile(55, 3)

[/lua]

Is what you’re looking for. It unlocks the tile from either locked drawn or locked erase mode.

  • Caleb

Thx Caleb!

Thanks for your help, once again Caleb.

I’ve got an issue now with a tilemap not displaying on my Android test device (black background displayed - but sprites are fine).

It works fine in the simulator. Can anyone offer any pointers?

I know there’s a size limit on images displayed on devices but I thought a larger image made from 32x32 pixel tiles would be OK.

The thing is that I’ve sliced up a larger graphic to do this, so each tile is unique.

My main image is a png - 32.3MB (16000 x 672 pixels)

It’s split up into 32 x 32 pixel tiles to form a tilemap of 500 x 21 pixels.

I might be trying to do the impossible here - is there a fix? Any idea what the maximum size might be?


I’ve just scaled it down to 1.3MB 3200 x 134px and made a tilemap of 100x2 tiles, each of size 32x67 pixels - same result. Tilemap is black but sprites render and function fine. The object platform layer is functioning within the tilemap.

I’m not sure if it’s how I’m using Tiled, but all previous tests have been fine…

–Fixed - I’ve had issues with Photoshop loading and saving png’s - I put it down to that… opened and saved in Mac Preview app and it’s fine…

This first suggestion worked really well for me. I did have to go into misc/functions.lua and edit around line 100 to make sure that anything with the prefix “animation:” was automatically added. I just had it stick it into props, for simplicity. Interestingly enough, this put it into tile.props.animation.whateverKeyIdSpecified. Following that, I added a function to tile inside layers/tileLayer.lua after properties were added (but before it was placed into the layer) which would allow me to change the image that’s displayed for that tile.

My version of dusk, obtained February of this year, already used sprites in the way that you described, Caleb. This made it really easy to change which tile-image is displayed simply by executing tile:setFrame( GIDFromMyAnimationProperties + 1 ).

Hey, everyone! I just released an update that brings Bang, a new serialization notation, to Dusk. It’s meant to replace JSON as the notation of choice. You can read more about it at http://gymbylcoding.github.io/posts/dusks-own-serialization-format.html

Speaking of which, I’ve made my “tech site” public at gymbylcoding.github.io - you can watch the GitHub repository if you want. I’ll be using that site for Dusk status updates and other goodies.

Enjoy!

  • Caleb

One question:
My current testproject with a simple Tiled map is crashing on the device (iPad2) but in the simulator running perfectly. I have no idea where to start looking for the problem because I don’t get an error from the device.

I’m using dusk for creating a map and the jumper pathfinding lib to get a path for a sprite via the A-algorithm. I’m using Glider.

Not so fency stuff but somehow the iPad2 is starting it, but I only can see some of the physics objects and the map isn’t even drawn. Can it be a memory issue with the map? Where are the limits for map files? It isn’t so big… only 40x40 Tiles with 50px each.

Any ideas?

Thx for all help!

Best,

Daniela

Any margin or spacing on your tiles? I’m fairly sure the texture limit of iOS is 2048, and 40x40*50x50 makes 2000x2000. Anything even slightly more could potentially go beyond the texture size.

  • Caleb

Thx Caleb for your help. I looked into the texture size problem but couldn’t find anything, so I tested everything else and found the problem:

The parsing of the json file is working on the simulator but not on the device. Somehow the data I get from the file is not working on the device, so the code stops when the data is read. I now will look into this.

thx again!

I really love dusk btw :wink:

One other question: I have looked into the json problem but I can’t find something wrong with the code. I now want to use Tiled to export lua files of the map. Can you please tell me how I can read the infos from the generated lua file into a table?

UPDATE: I think I got it… just used “require” to get the data and now everything works. :slight_smile:

How can I get more than one tileset to work in dusk?

Lua support isn’t as solid as JSON - for maximum stability, you should use JSON. If you’re attempting to read the JSON file other than Dusk just loading it (via dusk.buildMap(“map.json”)), that could be a problem - once I had my game not work for a long time because I was trying to open files in the resource directory in the wrong way.

On the other hand, if it’s only Dusk doing it, can you PM me your JSON file so I can give it a look?

[EDIT: Didn’t see your other question]: Just make multiple tilesets in Tiled and it should work just fine in Dusk.

  • Caleb

Thx for your fast feedback.

Regarding the JSON file: I’m still using it for everything Dusk related, but I’m now also export a lua file from Tiled to get a table I have access to in lua because I couldn’t get the Corona “json.decode” to work. It worked on the simulator but not on the device somehow. So with the lua table everything works fine and JSON is still used with Dusk.

About the multiple tilesets I wanted to create a third tile layer using a second tileset. I have build it in Tiled and I could show some of the new Tileset tiles on my tile layer 1 but I can’t see anything I create on the third tile layer which should be on top of all the other layers. Do I need to use an object layer inbetween tile layers maybe? Or do I have to add some properties before I can see a third tile layer?

Lua maps and JSON maps have a few differences; you might want to watch out for that.

You can load a JSON map (just read the data) with dusk.loadMap(filename), then you can build it by passing the loaded data in to dusk.buildMap:

[lua]

local mapData = dusk.loadMap(“map.json”)

local map = dusk.buildMap(mapData)

– Use mapData for other stuff

[/lua]

As for multiple tilesets, good catch! I just added a commit that should fix that.

  • Caleb

THANK YOU!

:slight_smile: