In this post, I’ll show you how to build a simple moving clock with Corona SDK. This tutorial uses display objects instead of images to keep things simple. Instead of walking through all of the pieces of code, I’ve listed the full script below. Feel free to drop this into your next project or modify as you see fit.

–Hide status bar from the beginning
display.setStatusBar( display.HiddenStatusBar )

— Set Variables
_W = display.contentWidth; — Get the width of the screen
_H = display.contentHeight; — Get the height of the screen

clockBorder = display.newCircle(_W/2,_H/2,125)
clockBorder.strokeWidth = 5

hourHand = display.newLine(_W/2,_H/2,_W/2,80)
hourHand.width = 5

minuteHand = display.newLine(_W/2,_H/2,_W/2,47)
minuteHand.width = 3

secondHand = display.newLine(_W/2,_H/2,_W/2,37)
secondHand.width = 2

local function updateClock(e)
local currentTime =“*t”)
secondHand.rotation = currentTime.sec * 6
minuteHand.rotation = currentTime.min * 6
hourHand.rotation = currentTime.hour * 30 + (currentTime.min * 0.5)

timer.performWithDelay(1000, updateClock, 0)

If you have any particular questions about the code above, please let me know in the comments.

Leave a Reply

Your email address will not be published. Required fields are marked *
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>