Regarding animated tiles can you please hint where to start? Is it possible to access tiles by their number, so this tiles can be ‘overwritten’ by animated sprites? Or something like this?
So for example you can edit a map with static images and then manually change some of the tiles from the map with animated sprite tiles.
Edit the Dusk code itself and add animated tiles
This would be the “feature” I was referring to. The way I was planning to implement this was through properties. Those properties will have a special prefix, like physics:, tiles:, etc. Like so:
[lua]
animation:enabled : true
animation:options : !json! {“start”: 1, “count”: 5}
[/lua]
Or something like that. Then, the animation data is added to the object. Right now, Dusk creates tiles with display.newImageRect; for animated tiles, you’d need to make a check for whether the tile enables animation, then build a sprite if it does. Each tileset is a plain image sheet internally.
You can start with checking out line 93+ in Dusk/dusk_core/layers/tilelayer.lua. That’s where the tile creation code starts.
Use object layers or properties to make animated tiles
This is more of a temporary but quick fix. Basically, you’d be creating either objects at specific locations with custom properties, or one big property table data element for them and load the animations manually (by iterating through with an object iterator) in your code.
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…
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 -
Currently, Dusk only supports map-wide scale along with the camera movement. In other words, map:scale(), not map.layer[1]:scale().
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.
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 ).
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.
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 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.
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
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.
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.
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?
So far everything is working fine but I have another question:
How can I change a tile into another tile from an tileset image? Something like: The tile from tileset1 with ID 5 is grass and it should become rock from tileset2 with ID75 when the character is doing some action or moving over this tile.
Jack, can you please post a more detailed sample on how you did include animated tiles, starting from adding the properties and samples of the code and functions?
I was just wondering exactly how fast Dusk really is. As you most likely know, speed hasn’t ever really been a main focus of Dusk; Dusk is more of a awesome-features-and-really-easy-to-use engine, with speed as a plus.
Hint: I had to encode the map as Lua because JSON took too long to parse.
(ok, so that was more of an interesting fact than a hint. But it is true.)
Hint #2: The map file is ~75 Mb
By the way, here’s the source code for the program in the video, with the irrelevant code cut out (display.setStatusBar, etc., as well as the drag+drop code in main.lua)
[lua]
local dusk = require(“Dusk.Dusk”)
print(“Loading Lua data…”)
local mapData = dusk.loadMap(“impossibly_huge.lua”)
print(“Finished loading Lua data.”)
print(“Building map…”)
local map = dusk.buildMap(“tests/benchmarks/impossibly_huge.lua”)
print(“Done!”)