Dusk Engine

Ok. I’ve just pushed a commit that allows you to “un-sync” a single tile from the animation. Basically what you’ll do is this:

map.layer[1].tile(x, y):setSyncAnimation(false)

Then, it’ll drop off the grid and let you use it just as a sprite tile. It’ll still be culled, though, so beware. It just won’t automatically animate in sync to the other tiles.

And thanks for the kind words :).

  • Caleb

Thx for this update!

I still can’t figure out how to prevent the tiles which aren’t on the visible screen but outside from animating? I can’t access them because of the culling I guess? How is it possible to give each tile a static (not animated) :setFrame(X) value… on screen or not?

The only way it seems to work (most of the time) is to disable the following lines in dusk_core/run/anim.lua:

(lines 179+)

if d.watchTile then                         --d.watchTile:setFrame(((d.currentFrame + 1) % d.frameCount) + 1)                         --d.watchTile:play()                         --anim.sync(d, d.watchTile.frame) end

Then I can access the tiles like this (on screen and off screen):

for x=1,16 do        for y=1,16 do              if map.layer["tiles"].tile(x,y) then                     if map.layer["tiles"].tile(x,y).sequence then                         -- lock tile                         map.layer["tiles"].\_lockTileDrawn(x,y)                         map.layer["tiles"].tile(x,y):play()                     end                     if map.layer["tiles6"].tile(x,y).sequence  then                         map.layer["tiles6"].\_lockTileDrawn(x,y)                         map.layer["tiles6"].tile(x,y):setFrame(2)                         map.layer["tiles6"].tile(x,y):pause()                                              end              end        end end

BUT I don’t know what removing the lines in anim.lua is doing to the whole code and I guess it will cause problems in some other areas!?

The :setSyncAnimation() stops or resumes the tile from syncing with other tiles’ animation. Like so:

 if map.layer["tiles6"].tile(x,y).sequence then map.layer["tiles6"].\_lockTileDrawn(x,y) map.layer["tiles6"].tile(x,y):setSyncAnimation(false) -- Turns off auto animation syncing map.layer["tiles6"].tile(x,y):setFrame(2) -- Now this tile animates independently from others end
  • Caleb

Thx for the details Caleb.

One thing I just found out: When you are using the following lines to get sharp graphics:

display.setDefault("minTextureFilter", "nearest") display.setDefault("magTextureFilter", "nearest")

you have to use images or image sheets (frames) with the power of two! Otherwise the graphics will not look 100% like the originals! Some pixels can be off or will be off when the images are moved for example. To avoid this problem the images should always use the power of two (means for example have the size 16,32,64,128 and so on)

Is it possible to prevent object culling when objects move outside of the visible screen?

I just noticed their x and y value is unknown, when they move outside of the screen… but sometimes I need to access them.

The only things that are culled are tiles. So if Dusk is culling objects as well… That’s unexpected :slight_smile:

What exactly is happening?

  • Caleb

I wondered dusk is doing this :wink: but I just figured it out: It was a coincidence in my function call. I forgot to start the function with a parameter and it happened exactly when the objects where moving out of the screen… :slight_smile:

Ok. Glad you got it figured out.

  • Caleb

Hello,

Great work here Caleb. My tiled map that I’m using with Dusk is 1800x1800 with the tiles at 32px. My pc has a hard time loading it, and my phone just crashes. I know it’s a big map, but maybe you have some advice. I’ve thought about loading multiple maps that would equal up to the desired size, and moving them along the x/y grid simultaneously. What do you think?

Well… Over three million tiles is a lot, though technically enough memory allows you to have however big of a map you want (as a test, I once loaded twenty-five million tiles into the simulator). Unfortunately, some devices don’t have that much free memory (although the iPad handled the 25,000,000 nicely). You can move your maps as you said, or, for a better solution, split your game up into multiple stages and load the new map when the player goes through a door or passage or something. You could work and make this pretty seamless if you want to go for a giant “world” feel. That would have the dual purpose of keeping things smooth and fast, because you don’t have 10 or 15 maps loaded at the same time.

  • Caleb

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

Hi

Is there a way to tint all tiles in a layer or tint a tileset?

I’m back! Post away!

  • Caleb

@sakib.farid:

Not currently. Sorry about that :). This might be something I add the next time I have a Dusk concentrated coding session.

  • Caleb

Hi Caleb,

I have been having some issues with loading tile maps into my scene.

I build the map in my code and it launches with no errors, but the tiles are all mixed up and there are large gaps in between tiles.

I was thinking this may have something to do with the spacing on the tileset. Does the Dusk Engine have any limitations concerning margins and tile spacing?

Thankyou in advance.

There are no issues with margin or spacing as far as I know. Can you give me some more information about your map? What’s your tile size, margin, spacing, and config.lua settings? Does this issue occur on every simulator, or just one?

  • Caleb