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.
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:
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
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)
I wondered dusk is doing this 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…
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.
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.
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.
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).
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.
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?
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?