Manipulating UV data on a sprite is a fun way to do all sorts of things, such as
animating grass or in this case, animating a progress bar. This mimics the progress style you see on OSX.
setVirtualResolution(640,480)
// Load progress bar image and set image wrap mode to repeat
// image is 12x20
pimg = loadImage("progress.png")
setImageWrapU(pimg, 1) : setImageWrapV(pimg, 1)
progress = createSprite(pimg)
setSpritePosition(progress, 100,150)
// original width of progress image, needed for UV calculations
progressBaseWidth# = getSpriteWidth(progress)
do
// Scroll the UV texture and wrap the value for numerical safety reasons
u# = u# - 0.03
if u# <= 0 then u# = u# + 1
setSpriteUVOffset(progress, u#, 1)
// Use arrow keys to grow/shrink progress bar
if getRawKeyState(37) = 1
w = getSpriteWidth(progress)-4
setSpriteSize(progress, w, 20)
s# = progressBaseWidth# / w
setSpriteUVScale(progress, s#, 1)
endif
if getRawKeyState(39) = 1
w = getSpriteWidth(progress)+4
setSpriteSize(progress, w, 20)
s# = progressBaseWidth# / w
setSpriteUVScale(progress, s#, 1)
endif
Sync()
loop
"I like offending people, because I think people who get offended should be offended." - Linus Torvalds