Reading dimensions of sprites during control stage.
Posted: Tue Sep 28, 2021 2:24 pm
Why ?
For Dana, I need precise control of the size/position/x-y ratio of sprites in rendering.draw_sprite(). For some kind of sprites (ex: technology, entities) which don't have standard dimensions like item sprites, this doesn't seem possible with the current API.
Proposition
1) New read-only class/concept to get informations about sprites.
I would rather have the sizes in tiles instead of pixels, since coordinates in the rendering API are already mostly in tiles. I also assume pixel size may be dependent on "Graphics -> Sprite resolution" settings, so would be player-specific.
2) New method in LuaGameScript to get this object
Example usecase
Rendering a technology sprite in a 1x1 tile square, occupying as much room as possible while keeping the x/y ratio:
For Dana, I need precise control of the size/position/x-y ratio of sprites in rendering.draw_sprite(). For some kind of sprites (ex: technology, entities) which don't have standard dimensions like item sprites, this doesn't seem possible with the current API.
Proposition
1) New read-only class/concept to get informations about sprites.
Code: Select all
LuaSpriteInfo {
valid: boolean -- Is this object valid ?
x_size: number -- X dimension of this object (preferably in tiles)
y_size: number -- Y dimension of this object (preferably in tiles)
}
2) New method in LuaGameScript to get this object
Code: Select all
LuaGameScript::get_sprite_info(spritePath: string) -> LuaSpriteInfo
Rendering a technology sprite in a 1x1 tile square, occupying as much room as possible while keeping the x/y ratio:
Code: Select all
local sprite_path = "technology/foobar"
local sprite_info = game.get_sprite_info(sprite_path)
local scale = math.min(1 / sprite_info.size_x, 1 / sprite_info.size_y)
local id = rendering.draw_sprite{
sprite = sprite_path,
surface = 1,
position = {0,0},
x_scale = scale,
y_scale = scale,
}