How to get the dimensions of an entity at runtime?
Posted: Fri Jan 14, 2022 1:01 pm
I'm having a minor problem with a GUI where I want to center the camera on an entity:
The entities are based on different prototypes (basically, all these prototypes are variations of the same vanilla prototype), so they will look differently and their graphics may be of a different size. In order to center them vertically, I need to apply OFFSET. However, as some entities are higher than others, I'd need to adjust the value of OFFSET. That would be easy if there was a way to get at the dimensions of the graphics, but it seems that entity.prototype does not have any relevant information I could use.
I've compared the values of different prototypes, but their respective selection_box, collision_box, and drawing_box had identical values. Height/size of animations is what I'd really need, but that information is only available during the data stage.
The different entities I want to show in my GUI come from different mods, so I'm not really in control of them. Is there a way to get the size of graphics of random entities during the control stage?
Code: Select all
elements = my_gui[preview_frame]
for e, entity in pairs(entities) do
element = entity.name.."-camera"
elements.add{
type = "camera",
name = element,
zoom = zoom,
surface_index = entity.surface.index,
position = {entity.position.x, entity.position.y - OFFSET},
}
…
end
I've compared the values of different prototypes, but their respective selection_box, collision_box, and drawing_box had identical values. Height/size of animations is what I'd really need, but that information is only available during the data stage.
The different entities I want to show in my GUI come from different mods, so I'm not really in control of them. Is there a way to get the size of graphics of random entities during the control stage?