{"id":15722608,"url":"https://github.com/whiteboxdev/library-defold-tilemap-animator","last_synced_at":"2025-04-15T05:47:32.020Z","repository":{"id":74948329,"uuid":"245587513","full_name":"whiteboxdev/library-defold-tilemap-animator","owner":"whiteboxdev","description":"Defold Tilemap Animator provides runtime tile animations in a Defold game engine project.","archived":false,"fork":false,"pushed_at":"2024-05-24T16:14:33.000Z","size":830,"stargazers_count":34,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T05:47:29.417Z","etag":null,"topics":["defold","defold-library"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whiteboxdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-07T07:25:42.000Z","updated_at":"2025-03-16T00:06:25.000Z","dependencies_parsed_at":"2024-05-16T06:13:59.876Z","dependency_job_id":"ca3a3c43-2373-4233-81aa-e0f60793c125","html_url":"https://github.com/whiteboxdev/library-defold-tilemap-animator","commit_stats":null,"previous_names":["whiteboxdev/library-defold-tilemap-animator"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whiteboxdev%2Flibrary-defold-tilemap-animator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whiteboxdev%2Flibrary-defold-tilemap-animator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whiteboxdev%2Flibrary-defold-tilemap-animator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whiteboxdev%2Flibrary-defold-tilemap-animator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whiteboxdev","download_url":"https://codeload.github.com/whiteboxdev/library-defold-tilemap-animator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016316,"owners_count":21198832,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["defold","defold-library"],"created_at":"2024-10-03T22:08:38.600Z","updated_at":"2025-04-15T05:47:32.002Z","avatar_url":"https://github.com/whiteboxdev.png","language":"Lua","funding_links":[],"categories":["Libraries"],"sub_categories":["Programming Language"],"readme":"# Defold Tilemap Animator\n\nDefold Tilemap Animator provides runtime tile animations in a Defold game engine project.\n\nPlease click the ☆ button on GitHub if this repository is useful or interesting. Thank you!\n\n![alt text](https://github.com/whiteboxdev/library-defold-tilemap-animator/blob/master/assets/thumbnail.png?raw=true)\n\n## Installation\n\nAdd the latest version to your project's dependencies:  \nhttps://github.com/whiteboxdev/library-defold-tilemap-animator/archive/master.zip\n\n## Configuration\n\nImport the dtile Lua module into any script:\n`local dtile = require \"dtile.dtile\"`\n\nInstead of defining tile animations in Defold's `tilesource` file, dtile requires you to define your own tile animations in table format:\n\n```\nlocal animation_groups = {\n    [\u003ctile_id\u003e] = { sequence = { \u003ctile_id_1\u003e, \u003ctile_id_2\u003e, ... }, trigger = \u003cboolean\u003e, frequency = \u003cvalue\u003e, reset = \u003cboolean\u003e },\n    ...\n}\n```\n\n1. `tile_id`: Tile id which begins your animation. This value can be found by hovering over the respective tile in your tilesource file.\n2. `sequence`: Table defining this animation sequence. This allows you to create custom animation sequences, rather than being forced to conform to presets.\n3. `trigger`: Indicates that this is a *trigger* animation rather than a *loop* animation. Trigger animations can be activated by a script at any time and roll exactly once.\n4. `frequency`: Animation speed measured in `sequence` frames per second.\n5. `reset`: *Only needed if this is a trigger animation.* Indicates that this animation should regain its start tile graphic on completion. Otherwise, this animation will quit rolling once the final `sequence` frame has been reached.\n\nEach animation you wish to create should be added as an entry in the `animation_groups` table.\n\nYou are ready to initialize dtile. Call `dtile.init()` in your script:\n\n```\nlocal dtile = require \"dtile.dtile\"\n\nlocal animation_groups = { ... }\n\nfunction init(self, dt)\n    dtile.init(animation_groups, \u003ctilemap_url\u003e, \u003clayers\u003e)\n    dtile.toggle_message_passing(true, msg.url())\nend\n```\n\n1. `animation_groups`: Table of tile animations explained above.\n2. `tilemap_url`: URL to the animated tilemap.\n3. `layers`: Table of hashed tilemap layer ids. For example: `{ hash(\"background\"), hash(\"midground)\", hash(\"foreground\") }`.\n\nIf you wish to receive animation progress updates in your `on_message()` function, call `dtile.toggle_message_passing()`. This feature is set to `false` by default. If set to true, also pass in a URL to the script that will receive dtile messages.\n\ndtile will now begin animating your tilemap. Of course, only loop tiles will show any activity. To animate a trigger tile, call `dtile.animate()`.\n\nIf you would like to cancel all animations--both loops and triggers--call `dtile.final()`. To start animating again, call `dtile.init()`.\n\n## API: Properties\n\n### dtile.msg\n\nTable for referencing messages posted to your script's `on_message()` function:\n\n```\ndtile.msg =\n{\n    animation_loop_complete = hash(\"animation_loop_complete\"),\n    animation_trigger_complete = hash(\"animation_trigger_complete\")\n}\n```\n\n1. `animation_loop_complete`: Posted when a `trigger = false` animation group completes its `sequence`. The `message.tile_id` field contains the tile id which begins this animation sequence.\n2. `animation_trigger_complete`: Posted when a trigger tile completes its `sequence`. The `message.tile_id` field contains the tile id which begins this animation sequence. The `message.x`, `message.y`, and `message.layer` fields contain this tile's `x` position, `y` position, and hashed `layer` id on the tilemap.\n\n## API: Functions\n\n### dtile.init(animation_groups, tilemap_url, tilemap_layers)\n\nInitializes dtile. Must be called in order to begin animating tiles.\n\n#### Parameters\n1. `animation_groups`: Table defining your custom animation groups.\n    1. `tile_id`: Tile id which begins your animation.\n    2. `sequence`: Table defining this animation sequence.\n    3. `trigger`: Indicates that this is a trigger animation rather than a loop animation.\n    4. `frequency`: Animation speed measured in `sequence` frames per second.\n    5. `reset`: Indicates that this animation should regain its start tile graphic on completion. *Only needed if this is a trigger animation.*\n2. `tilemap_url`: URL to the animated tilemap.\n3. `layers`: Table of hashed tilemap layer ids.\n\nThe format for the `animation_groups` table is as follows:\n\n```\nlocal animation_groups =\n{\n    [\u003ctile_id\u003e] = { sequence = { \u003ctile_id_1\u003e, \u003ctile_id_2\u003e, ... }, trigger = \u003cboolean\u003e, frequency = \u003cvalue\u003e, reset = \u003cboolean\u003e },\n    ...\n}\n```\n\n---\n\n### dtile.final()\n\nCancels all loop and trigger animations and disables all animation functions. This is useful when transitioning between tilemaps, among other cases.\n\n---\n\n### dtile.animate(x, y, layer)\n\nActivates a trigger animation. Does nothing if a trigger animation is not assigned to the specified tile.\n\n#### Parameters\n1. `x`: X-coordinate of tile.\n2. `y`: Y-coordinate of tile.\n3. `layer`: Hashed tilemap layer id of tile.\n\nIf you do not specify a `layer`, then dtile will activate all trigger animations at `[x, y]` regardless of layer.\n\n---\n\n### dtile.reset(x, y, layer)\n\nResets a trigger animation to its first frame. Does nothing if a trigger animation is not assigned to the specified tile.\n\n#### Parameters\n1. `x`: X-coordinate of tile.\n2. `y`: Y-coordinate of tile.\n3. `layer`: Hashed tilemap layer id of tile.\n\nIf you do not specify a `layer`, then dtile will reset all trigger animations at `[x, y]` regardless of layer.\n\n---\n\n### dtile.get_tile(x, y, layer)\n\nGets a tile in the loaded tilemap.\n\n**Note:** This is a replacement for Defold's built-in [tilemap.get_tile()](https://defold.com/ref/tilemap/#tilemap.get_tile:url-layer-x-y). This function accounts for animations.\n\n#### Parameters\n1. `x`: X-coordinate of tile.\n2. `y`: Y-coordinate of tile.\n3. `layer`: Hashed tilemap layer id of tile.\n\nIf you do not specify a `layer`, then dtile will return a table containing the tile at `[x, y]` in each layer:\n\n```\n{\n    [\u003clayer\u003e] = \u003ctile_id\u003e,\n    ...\n}\n```\n\n#### Returns\n\nReturns a tile id or a table of tile ids.\n\nEven if the tile is playing an animation, the first frame is returned. For example, a flower tile is animated across three frames and therefore three tile ids:\n\n```\nflower_sequence = [ tile_id = 1, tile_id = 2, tile_id = 3 ]\ncurrent_tile_id = 2 // The flower animation is on its second frame.\ndtile.get_tile(\u003cflower\u003e) // Returns '1'.\n```\n\nTo get the actual current tile id instead of the first frame, use [tilemap.get_tile()](https://defold.com/ref/tilemap/#tilemap.get_tile:url-layer-x-y).\n\n---\n\n### dtile.set_tile(layer, x, y, tile, h_flipped, v_flipped)\n\nReplaces a tile in the loaded tilemap with a new tile.\n\n**Note:** This is a replacement for Defold's built-in [tilemap.set_tile()](https://defold.com/ref/tilemap/#tilemap.set_tile:url-layer-x-y-tile-[h-flipped]-[v-flipped]). This function accounts for animations.\n\n#### Parameters\n\nSee [tilemap.set_tile()](https://defold.com/ref/tilemap/#tilemap.set_tile:url-layer-x-y-tile-[h-flipped]-[v-flipped]).\n\n---\n\n### dtile.has_trigger_animation(tile_id)\n\nChecks if a trigger animation is assigned to the specified `tile_id`.\n\n#### Parameters\n\n1. `tile_id`: Tile id number.\n\n#### Returns\n\nReturns a `bool`.\n\n---\n\n### dtile.toggle_message_passing(flag, url)\n\nToggles dtile's ability to post animation update messages to your script's `on_message()` function.\n\n#### Parameters\n1. `flag`: Boolean indicating whether to post messages.\n2. `url`: URL to the script that should receive messages.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhiteboxdev%2Flibrary-defold-tilemap-animator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhiteboxdev%2Flibrary-defold-tilemap-animator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhiteboxdev%2Flibrary-defold-tilemap-animator/lists"}