|
|
|
All purpose status bar
Added on 12/9/1999
|
Use this to track the status of any property or variable. Can be used for downloads, energy bars, etc.
--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)
property spriteNum, monitorValue, maxValue, constant, direction, maxRect
on getPropertyDescriptionList me
p_list = [:]
p_list.addProp(#monitorValue, [#format : #string, #comment : "What value to compare:", #default : "the timer / 60"])
p_list.addProp(#maxValue, [#format : #string, #comment : "Max value allowed:", #default : "500"])
p_list.addProp(#constant, [#format : #boolean, #comment : "Run automatically?", #default : true])
p_list.addProp(#direction, [#format : #symbol, #comment : "Direction to grow:", #default : #right, #range : [#right, #left, #up, #down]])
return p_list
end
on beginSprite me
maxRect = sprite(spriteNum).rect
calcSize()
end
on exitFrame me
calcSize()
end
on calcSize me
curValue = value(monitorValue)
topVal = value(maxValue)
if topVal = 0 then topVal = .001
if [#integer, #float].getOne(curValue.ilk) <> 0 and [#integer, #float].getOne(topVal.ilk) <> 0 then
--is a number, continue
if curValue > maxvalue then curValue = topVal
if curValue < 0 then curValue = 0
percentage = float(curValue)/float(topVal)
newRect = duplicate(maxRect)
case direction of
#right :
newRect[3] = maxRect[1] + integer(maxRect.width * percentage)
#left :
newRect[1] = maxRect[3] - integer(maxRect.width * percentage)
#up :
newRect[2] = maxRect[4] - integer(maxRect.height * percentage)
#down :
newRect[4] = maxRect[2] + integer(maxRect.height * percentage)
end case
sprite(spriteNum).rect = newRect
else
--not a number
put "Error, returned value is not a number"
end if
end
on getBehaviorDescription me
describe = "This is an all purpose bar slider. Drop it on the sprite that will be the indicator and assign it the values it will use to compare the current bar."
describe = describe & return & "For example, to track a sprite 5"s property called life against a max of 500, the first field would be entered as ..." & return
describe = describe & "sprite(5).life and the second field would be 500."
return describe
end
|
|