Quote: "Then i learn the basics from the master himeself"
I'm flattered
.
It's pretty straightforward if you don't mind the image getting 'squashed' as the health bar changes. Load the image, make a sprite out of it, and simply use SIZE SPRITE to change it to whatever length you need:
sync on : sync rate 60
`Variable Setup
#Constant HealthBarImage 1
#Constant HealthBarSprite 1
HealthBarWidth = 500
HealthBarHeight = 15
`Media Setup
`\\\\\\\\\\\\\\\\\\\\\\\\\
`Load your health bar image here
cls rgb(255,255,255)
ink rgb(10,10,0),0
text 0,0,"This is a Health Bar"
get image HealthBarImage,0,0,HealthBarWidth,HealthBarHeight
`\\\\\\\\\\\\\\\\\\\\\\\\\
sprite HealthBarSprite,10,10,HealthBarImage
`Main Loop
do
inc HealthBarWidth, rightkey()-leftkey()
if HealthBarWidth<0 then HealthBarWidth = 0
size sprite HealthBarSprite,HealthBarWidth,HealthBarHeight
sync
loop
If you don't want the image to get squashed, you'd have to use memblocks, which are a little more in-depth:
sync on : sync rate 60
`Variable Setup
`This is the base image
#Constant HealthBarImage 1
`This is the image that will be cut up and displayed
#Constant HealthBarCutImage 2
#Constant HealthBarSprite 1
HealthBarWidth = 500
HealthBarHeight = 15
`Media Setup
`\\\\\\\\\\\\\\\\\\\\\\\\\
`Load your health bar image here
cls rgb(255,255,255)
ink rgb(10,10,0),0
text 0,0,"This is a Health Bar"
get image HealthBarImage,0,0,HealthBarWidth,HealthBarHeight
`\\\\\\\\\\\\\\\\\\\\\\\\\
`Copy the image into the sprite image
make memblock from image 12,HealthBarImage
make image from memblock HealthBarCutImage,12
delete memblock 12
sprite HealthBarSprite,10,10,HealthBarCutImage
`Main Loop
do
inc HealthBarWidth,rightkey()-leftkey()
if HealthBarWidth<0 then HealthBarWidth = 0
CutImage(HealthBarImage,HealthBarCutImage,HealthBarWidth)
sync
loop
`This function will alpha out any pixels outside the desired width
function CutImage(BaseImage,TargetImage,Width)
make memblock from image 12,BaseImage
if Width>=image width(BaseImage)
`If the width is the same as or greater than the image, don't do anything
make image from memblock TargetImage,12
else
`Go through the memblock and set the alpha of any pixels past the width
`to 0.
for c=13 to get memblock size(12) step 4
inc rowcounter
if rowcounter>Width then write memblock byte 12,c+2,0
if rowcounter>image width(BaseImage) then rowcounter = 1
next c
make image from memblock TargetImage,12
endif
delete memblock 12
endfunction
Ask if you have any questions!
Diggsey: I have a spine and memory, but one memorable guy says he hates me. What am I?