If you have the time to render a bunch of images, you can do it a ‘quick and dirty’ method and replace a display object’s image with the object.fill method.
local progressBar = display.newImageRect( "percent100.png", 64, 16 ) progressBar.x, progressBar.y = display.contentWidth \* 0.5, display.contentHeight \* 0.5 local percentage = 100 local function changeBar( amount ) -- make sure it's a multiple of 10 and within the range amount = math.round( amount \* 0.1 ) \* 10 if amount \< 0 then amount = 0 else if amount \> 100 then amount = 100 end -- change the image of the display object progressBar.fill = { type = "image", filename = "percent" .. amount .. ".png" } end timer.performWithDelay( 1000, function() percentage = percentage - 10 changeBar( percentage ) end, 10 )
This is assuming you have files called percent100.png, percent90.png, percent80.png, and so on all the way down to percent0.png. With this method, you can make the image as nicely detailed as possible, instead of having to just render one on the fly, and you could make it any shape or icon, i.e. a clock, an hourglass, etc.
Graphics 2.0’s new object.fill is a very appreciated method that makes it easy to change the image of an already-established display object without having to deal with setting up spritesheets and animation sequences.