Trouv / bevy_ecs_ldtk

ECS-friendly ldtk plugin for bevy, leveraging bevy_ecs_tilemap
Other
627 stars 73 forks source link

fix: use entity definition tile size instead of entity instance tile size as basis when calculating ldtk entity scale #271

Closed Trouv closed 7 months ago

Trouv commented 7 months ago

Closes #267

LDtk populates an EntityInstance's __tile field if any tile is used when visualizing that entity in-level. This is normally just the entity's editor visual, but if that entity is given a singular tile field instance and has no editor visual, it might use that instead. Currently, bevy_ecs_ldtk uses this field to calculate the scale when spawning EntityInstances. This can lead to unexpected behavior. The scale of entity instances with no entity visual should correlate to the size of the instance in the level. This might not be the case for entities that have a tile field despite having no editor visual. The solution implemented here is to use the tileRect field of the entity definition instead of the __tile field of the entity instance.

To be honest, I'm not totally satisfied with this solution either. The entity spawning process is currently designed to match the visuals in the editor when using sprites. However, it's not perfect at doing this, and using the transform's scale to accomplish this makes the logic affect a lot more components than just the sprite. It also affects colliders, for example. However, for now, this should be a satisfactory fix that does not affect many users negatively