Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

david-torres/DT_Healthbar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DT_Healthbar is a simple health bar implementation for Gideros Mobile. Could also be used as a progress bar.

Initialization

-- create the health bar
local healthbar = DT_HealthBar.new({
    width = 100,
    height = 10,
    front_color = 0x00FF00,
    back_color = 0xFF0000,
    max_value = 100 -- how "full" can this bar be?
})

-- add it to stage
stage:addChild(healthbar)

-- position where you want it to be
_W = (application:getContentWidth() * 0.5) - (healthbar:getWidth() * 0.5)
_H = (application:getContentHeight() * 0.5) - (healthbar:getHeight() * 0.5)

healthbar:setPosition(_W, _H)
-- healthbar:setRotation(-90) -- flip it vertical

Empty a full health bar

healthbar:fill()

local decrement_healthbar = function()
    healthbar:subtract(10)
end

local health_down = Timer.new(600, 10)
health_down:addEventListener(Event.TIMER, decrement_healthbar)
health_down:start()

Fill an empty health bar

healthbar:empty()

local increment_healthbar = function()
    healthbar:add(10)
end

local health_up = Timer.new(600, 10)
health_up:addEventListener(Event.TIMER, increment_healthbar)
health_up:start()

About

A simple healthbar implementation using Gideros

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages