heygleeson / godot-ldtk-importer Goto Github PK
View Code? Open in Web Editor NEWLDTK Importer for Godot 4
License: MIT License
LDTK Importer for Godot 4
License: MIT License
I would like to be able to get info, like in grid names. Let's say I have an int grid layer
In the generated tileset8x8.res I can see this
I would like to be able to map these names to the atlas source id. Why? Let's say I collide with a tile and I want to know which sound to emit based on the material, that I mapped in ldtk to a int in the intgrid layer. But I can't get any of that info using the post import scripts.
Would it be possible to get more info in the level or tileset post import?
I want to procedurally generate a world for my game where the level order is randomly generated and to do that, I need to randomly instantiate the levels. But, as far as I know, there is no way to do that currently.
Hi I'm pretty new in the Godot and LDtk i could not get how to import a collision?
I successfully imported ldtk file, it has 2 layers but do not have any mentions of collisions itself.
Thank you in advance.
I'm new to game development and LDtk. I want to try implementing lazy loading to optimize performance. I also want to try storing a lot of levels in a GridVania world that I can use as a pool to generate a dungeon layout.
It seems I have to load every level at once to utilize an imported world.ldtk
scene. But LDtk has the option to export individual level files. Is there a way I can utilize these files or implement some other logic so I can achieve lazy loading, etc.?
The best thing I could think of is injecting a VisibleOnScreenEnabler2D
underneath every level node, but that seems very janky and still requires the loading of every level at once.
This is more of a question than an issue, so apologies for the out of place issue.
I'm using the Post-Import script for the EntityLayers to replace entity layers with my own custom BoundingBox Scene (based on an Area2D which needs a collision shape child). That is working correctly.
However, I would like to add a CollisionShape2D as a child to that BoundingBox node and have both appear in the final import. Currently, the BoundingBox appears in the final world, but does not have any children.
I believe this is from the owner not being set, but I am not sure how to set the owner of the CollisionShape2D correctly in the post-import script. I thought this would be handled by code that is run later, but it appears not.
Here's my current import script:
@tool
## Entity Post Import Example, showcasing how to handle EntityRefs.
const Util = preload("res://addons/ldtk-importer/src/util/util.gd")
const boxScene = preload("res://scenes/bounding_box.tscn")
func post_import(entity_layer: LDTKEntityLayer) -> LDTKEntityLayer:
var entities: Array = entity_layer.entities
for entity in entities:
# Create entity node (simple example)
var bounding_box = boxScene.instantiate()
bounding_box.position = entity.position
# Create RectangleShape2D from entity shape
var new_rect: RectangleShape2D = RectangleShape2D.new()
new_rect.size = entity.size
# Create CollisionShape2D with shape
var new_collision_shape: CollisionShape2D = CollisionShape2D.new()
new_collision_shape.position = entity.position
new_collision_shape.shape = new_rect
# Add CollisionShape2D as child of BoundingBox (this is what is not working)
bounding_box.add_child(new_collision_shape)
new_collision_shape.owner = bounding_box # This doesn't seem to do anything
entity_layer.add_child(bounding_box)
# Update 'iid' to reference this entity node
Util.update_instance_reference(entity.iid, bounding_box)
# Add unresolved reference (e.g. EntityRef field)
if "Entity_ref" in entity.fields:
var ref = entity.fields.Entity_ref
if ref != null:
bounding_box.ref = ref
print("adding unresolved ref")
Util.add_unresolved_reference(bounding_box, "ref")
return entity_layer
Am I missing an obvious addition that makes the owner get set later on in the import process?
Importing custom data into Godot 4.2-beta4 has the data get offset by 1 on the X axis
Tiles with custom data in LDtk:
Tiles with custom data after imported into Godot:
Project files:
My Fishing Game.zip
Normally you have to enable Y-Sorting on a per-layer basis on the Tilemap - but since the Tilemap is created via import and can't be edited, is there a different way of accomplishing this?
This is most likely better with Github discussions but I was curious what a workflow looks like with entities.
The two avenues I can think of are using the hook for entities to instantiate scenes based on the entity date.
The challenges are... the JSON data is untyped because GODOT arrays are untyped and a bit more of a hassle
The other avenue is using the Placeholder Entities, grab a reference the entity, then at runtime, copy all the fields and then destroy it.
The downside is the overhead of needing to copy and destroy each placeholder.
I think you need to round up here. I am getting a off-by-1 error here and ceili
seems to fix it.
https://github.com/heygleeson/godot-ldtk-importer/blob/f07f927e1ba82a326a3fb94f7e144a1fbd920d1e/addons/ldtk-importer/src/tileset.gd#L114C22-L115
Something like:
var grid_w: int = ceili((definition.pxWid - margin) / (tile_size + separation))
var grid_h: int = ceili((definition.pxHei - margin) / (tile_size + separation))
I'm not entirely sure how the LDtk structure works, but looking at the file, you may just want to use the fields "__cWid" and "__cHei" rather than trying to calculate it from the pixel width.
In my case, __cWid is 31, but because the grid_w calc is hard rounding down, it ignores the last column and is getting 30 instead.
When placing Godot scenes during the entities post-import script; the scenes are unpacked and lose their 'prefab' status in the editor. This is due to the recursive set owner setting all sub nodes (including spawned sub-scenes and all of their children) to the world node.
for node in level.get_children():
Util.recursive_set_owner(node, world)
The intended effect is that all of the scenes which are spawned during post-import scripts are kept as sub-scenes with their 'Open in Editor' icon in tact. This keeps the reference to the scene and I can update all spawned scenes by just editing the scene for the entity.
A fix that I use is to place the post-import script for entities after the recursive set owner and set the owner of the sub-scene root node to the layer by hand. However; this is probably not workable as a general fix.
if (Util.options.entities_post_import):
var layers = level.get_children()
for layer in layers:
if not layer is LDTKEntityLayer:
continue
if (Util.options.verbose_output):
var entityLayerName = layer.get_parent().name + "." + layer.name
print("\n::POST-IMPORT ENTITIES: ", entityLayerName)
What probably needs to happen is that when traversing the tree to set the owners; spawned sub-scenes in post-import scripts only have their root node set the owner of; but not their children.
I think it might be possible to simplify the code that flips tiles since tile flipping was added back to Godot 4.2 (without the need to create alternative tiles).
As I import and open the .ldtk file into Godot, the editor shows a blank scene. A 16x16 tileset.res file in created, but there is no texture assigned to it. I can't find instructions on hold to make tileset textures work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.