Created
June 4, 2015 03:24
-
-
Save kyzentun/3ac24b0505bb6dcda416 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local player= Var("Player") | |
local texframe= false | |
local texture= false | |
local tex_width= 128 | |
local sprite_width= 16 | |
local life_sprite= false | |
local life_poses= {} | |
local function redraw_lives(self) | |
for i, pos in ipairs(life_poses) do | |
life_sprite:xy(pos[1], pos[2]):Draw() | |
end | |
end | |
return Def.ActorFrame{ | |
Def.ActorFrameTexture{ | |
Name= "This draws life_sprite to a texture at multiple positions.", | |
InitCommand= function(self) | |
texframe= self | |
self:setsize(tex_width, sprite_width):EnableAlphaBuffer(true):Create() | |
:hibernate(math.huge):SetDrawFunction(redraw_lives) | |
texture= self:GetTexture() | |
end, | |
Def.Sprite{ | |
Texture= THEME:GetPathG("midiman", "battery_piece.png"), | |
InitCommand= function(self) life_sprite= self end, | |
}, | |
}, | |
Def.Sprite{ | |
Name= "This actually draws the lives.", | |
InitCommand= function(self) | |
self:SetTexture(texture) | |
end, | |
LifeChangedMessageCommand= function(self, param) | |
if param.Player ~= player then return end | |
local total= param.LifeMeter:GetTotalLives() | |
local left= param.LifeMeter:GetLivesLeft() | |
local width_per_life= tex_width / total | |
local start= (sprite_width * .5) - width_per_life | |
life_poses= {} | |
for i= 1, left do | |
life_poses[i]= {start + (i * width_per_life), sprite_width * .5} | |
end | |
texframe:hibernate(0):Draw():hibernate(math.huge) | |
end | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment