module IconRenderer::Renderer
Overview
The main renderer module; familiarity with CrystalVips is highly recommended.
Extended Modules
Defined in:
renderer.crInstance Method Summary
-
#get_basename(gamemode : Constants::GamemodeType, icon : Int32) : String
Given a
gamemode
andicon
, makes an icon basename to be used in sheet lookups -
#render_icon(gamemode_type : Constants::GamemodeType, icon : Int32, col1 : Array(Float64), col2 : Array(Float64), col3 : Array(Float64) | Nil, glow : Bool, sheet : Assets::LoadedSpritesheet, robot_animations : Assets::Animations, spider_animations : Assets::Animations)
The main entrypoint for icon rendering; this should be all you need to render out an icon.
-
#render_layered(images : Array(Vips::Image), positions : Array(Tuple(Float32, Float32) | Nil), colors : Array(Array(Float64) | Nil), scales : Array(Tuple(Float32, Float32) | Nil), rotations : Array(Float64 | Nil))
Mainly for internal use; given an array of images, their sizes and colors, tints and composits them over each other.
-
#render_normal(basename : String, col1 : Array(Float64), col2 : Array(Float64), col3 : Array(Float64) | Nil, glow : Bool, sheet : Assets::LoadedSpritesheet)
Renders out a non-robot/spider icon.
-
#render_spicy(basename : String, col1 : Array(Float64), col2 : Array(Float64), col3 : Array(Float64) | Nil, glow : Bool, sheet : Assets::LoadedSpritesheet, animations : Assets::Animations)
#render_normal
, except for robots and spiders.
Instance Method Detail
Given a gamemode
and icon
, makes an icon basename to be used in sheet lookups
The main entrypoint for icon rendering; this should be all you need to render out an icon.
Example:
gamemode = IconRenderer::Constants::GamemodeType::Ball
icon_id = 35
# Load assets
ROBOT_ANIMATIONS = IconRenderer::Assets.load_animations("data/Robot_AnimDesc.plist")
SPIDER_ANIMATIONS = IconRenderer::Assets.load_animations("data/Spider_AnimDesc.plist")
basename = IconRenderer::Renderer.get_basename(gamemode, icon_id)
sheet = IconRenderer::Assets.load_spritesheet("data/icons/#{basename}-uhd.plist")
# Render out the icon
icon_img = IconRenderer::Renderer.render_icon(gamemode, icon_id, [0.0, 0.0, 0.0, 1.0], [255/255, 125/255, 125/255, 1.0], true, sheet, ROBOT_ANIMATIONS, SPIDER_ANIMATIONS)
# Trim it out
alpha = icon_img.extract_band(3)
left, top, width, height = alpha.find_trim(threshold: 0, background: [0])
icon_img = icon_img.crop(left, top, width, height)
# Write it to a file
icon_img.write_to_file("icon_rendered.png")
Mainly for internal use; given an array of images, their sizes and colors, tints and composits them over each other.
Renders out a non-robot/spider icon. You may be looking for #render_icon
.
Example:
SHEET = IconRenderer::Assets.load_spritesheet("data/icons/ship_44-uhd.plist")
icon_img = IconRenderer::Renderer.render_normal("ship_44", [0.0, 0.0, 0.0, 1.0], [255/255, 125/255, 125/255, 1.0], nil, true, SHEET)
#render_normal
, except for robots and spiders. Additionally requires animations for both.
Example:
SHEET = IconRenderer::Assets.load_spritesheet("data/icons/spider_01-uhd.plist")
SPIDER_ANIMATIONS = IconRenderer::Assets.load_animations("data/Spider_AnimDesc.plist")
icon_img = IconRenderer::Renderer.render_icon("spider_01", [0.0, 0.0, 0.0, 1.0], [255/255, 125/255, 125/255, 1.0], nil, true, SHEET, SPIDER_ANIMATIONS)