Skip to content

Latest commit

 

History

History
124 lines (108 loc) · 6.75 KB

README.md

File metadata and controls

124 lines (108 loc) · 6.75 KB

godot-LDtk-import METROIDVANIA EDITION

Program Version
Godot 3.3.3
LDtk 0.9.3

This fork focuses on optimising for metroidvania games. It'll load every level of the ldtk file into its own scene and a main scene where all the scenes will be loaded into.

Original description: Basic GDscript for importing LDtk files into the Godot game engine.

How to use:

  1. Copy the addons folder to your godot project folder.
  2. Enable LDtk Importer under Project Settings/Plugins.
  3. Add a .ldtk map file and any spritesheets you're using to your project folder.
  4. Check the import settings and make sure that they are correct! Refer to Options section for more info about each specific.
  5. The importer will load the levels into seperate scenes in the specified save path.
    • You are free to add resources to the scene, both the main and level scenes, just dont mess with the autogenerated node (and child nodes).
  6. Open the your-ldtk-file-main scene and select the RoomLoader`` node under AutoGenerated```, some values need to be entered manually.
    • Start Room: The (LDtk) level identifier for the room which the player should start in.
    • Level Scale: If your levels needs to be scaled to fit with the Godot resources.
    • Fade Duration: How long a single screen fade will be so the total room transition will be Fade duration * 2 + load times
    • Camera Nodepath: The node path to the camera object (needs to be Camera2D), if the camera is a child node in another scene, set that scene as the reference and make sure to have the Camera2D object be named Camera2D.
    • Player Nodepath: The node path to the player object/scene, will be used to move when changing level.
    • The other fields are autogenerated and should not be changed.
  7. Open the scene for the level which you specified as the starting level, create a new Position2D node and place as a spwn point in the room, now select the base node and set the Player Spawn Node reference. (The rest will be autogenerated)
  8. You should now be good to go! Be sure to play the main scene and not the specific level scenes!

Importing Collisions:

  • Create a layer called "Collisions", any tile in it will have a RectangleShape2D added to in a new layer.

Creating Doors:

  1. Go to the Enums tab in LDtk and press IMPORT -> HAXE SOURCE CODE, then select DIRECTIONS.hx located in the external folder in this project.
  2. Create a new Entity, these are the mandatory fields: (Note: The size can be reziable, the importer will sett the correct size for RectangleShape2D)
    • identifier:
      • TYPE: String
      • FIELD IDENTIFIER: identifier
      • DESCRIPTION: A identifier for the door you will be referncing when you should end up here when entering other doors, ie SecretBossDoor.
    • enter_direction:
      • TYPE: The DIRECTIONS enum created previously
      • FIELD IDENTIFIER: enter_direction
      • DESCRIPTION: Specifies which side of this door the player should be placed when entering TO this door.
    • target_level_identifier:
      • TYPE: String
      • FIELD IDENTIFIER: target_level_identifier
      • DESCRIPTION: Should be the LDtk level identifier of the level where the target door is located.
    • target_door_identifier:
      • TYPE: String
      • FIELD IDENTIFIER: target_door_identifier
      • DESCRIPTION: Will be the identifier field mentioned above for the door this door targets.
  3. Create a Entity layer called "Doors".
  4. Place the new Door entity and fill in the values.

Creating Light Occluders:

  1. Click the Tiles tab in LDtk
  2. Click on a tileset in the left menu and then on a tile
  3. Add data following the rules below.
// This will result in a simple square occluder filling the whole tile.
{ "light_occluder": true }
// This will result in a occluder having the shape spcified by the points.
{
  "light_occluder_shape": [
    {"x": 64, "y": 15},
    {"x": 64, "y": 64},
    {"x": 0, "y": 64},
    {"x": 0, "y": 0},
    {"x": 48, "y": 0},
    {"x": 55, "y": 3.2},
    {"x": 60, "y": 8.8}
  ]
}

Options:

  • Import_Collisions: If you want to import collision for the tiles (see import collisions below) or not
  • Import_Custom_Entities: If you want to import your own Resources (see entities), this should be set to true. Keep in mind that this will remove the other node options (they will still be imported, but only as Node2D).
  • Import_Metadata: If set, will import any fields set on the entities. If they have an exported property with the same name, it will set the value of the property with the value on LDtk, if they don't (or the plugin can't find it), they will be imported as metadata (using 'set_meta()') and can be retrieved later using 'get_meta()' on the imported object.
  • Import_YSort_Entities_Layer: If set, any Entities Layer whose name begins with "YSort" will be imported as a YSort node, and all the entities will be set as children of this YSort node.
  • Door_Collision_Mask: Sets which collision mask the door should be checking for changing level.
  • Scene_Save_Path: The path where all the scenes are goin to be saved. ie res://src/ldtkexample/

Tips:

  • IntGrid, Tiles, and AutoLayers are imported as TileMap Nodes.
  • Currently Entities have very basic functionality, checkout the testmap.ldtk for examples.
  • Make sure not to have the maps open when reimporting them, it'll mess stuff up.
  • If it comes out of sync with the LDtk file, just remove the node named AutoGenerated and it will create a fresh when importing next time.

Entities:

You can set up how your entities are imported:

  1. Create a new Entity
  2. Add a String Field Type
  3. Set the Field Identifier to: NodeType
  4. Set the Default Value to the type of Node
  5. Any fields added to the entity on LDtk can set properties on the object or be added as metadata if the option is set when importing (retrieve using the function 'get_meta()' on the object after importing)

Current node options are:

  1. If not using Custom Entities:
  • Position2D
  • Area2D
  • KinematicBody2D
  • RigidBody2D
  • StaticBody2D
  1. If using Custom Entities:
  • Position2D, Area2D, KinematicBody2D, RigidBody2D, and StaticBody2D will be imported as Node2D
  • Path to Resource (eg: 'res://Player.tscn'), this will use 'load().instance()' to create your existing node

Notes:

  • The example is using the tileset that comes with LDtk: Cavernas_by_Adam_Saltsman.png
  • The conversion functions: coordId_to_gridCoords(), tileId_to_gridCoords(), tileId_to_pxCoords() are from the LDtk documentation.

Updates:

Check CHANGELOG.md