brunch

You can make anything
by writing

C.S.Lewis

by 원강민 Oct 07. 2015

코로나 시계 샘플

뭐라도 만들어야 실력이 늘죠. ㅋ

코로나(Corona SDK)로 시계(Watch) 샘플을 만들었습니다. (-:
초급자용 샘플로 이런거 좋네요. ㅎㅎ


전체 소스 다운로드 :: 


[핵심 코드]

-- 배경 흰색
local background = display.newRect(0, 0, __appContentWidth__, __appContentHeight__)

-- 하단 'CORONA' 텍스트
local corona = display.newImage("colorbg.png")
corona.anchorX, corona.anchorY = 0.5, 1
corona:scale(0.5, 0.5)
corona.x, corona.y = __appContentWidth__ * 0.5, __appContentHeight__ - 20

--===============================  시계 생성 Begin ===============================--
-- 시계 그룹
local clockG = display.newGroup()
clockG.x,clockG.y = __appContentWidth__ * 0.5, __appContentHeight__ * 0.5

-- 시계 배경
local clockBg = display.newImageRect(clockG, "bg.png", 289, 289)
clockBg.anchorX, clockBg.anchorY = 0.5, 0.5
clockBg.x, clockBg.y = -0.5, -4

-- 시침
hourHandimg = display.newImageRect(clockG, "hour.png", 7, 110)
hourHandimg.anchorX, hourHandimg.anchorY = 0.5, 0.9

-- 분침
minuteHandimg = display.newImageRect(clockG, "min.png", 4, 122)
minuteHandimg.anchorX, minuteHandimg.anchorY = 0.5, 0.9

-- 초침
secondHandimg = display.newImageRect(clockG, "sec.png", 0.5, 137)
secondHandimg.anchorX, secondHandimg.anchorY = 0.5, 0.8
--===============================  시계 생성 End ===============================--

-- 시간 업데이트
local function updateCLock(e)
    dispTime.text = os.date("%H:%M:%S")

    local currentTime = os.date("*t")
    -- print ("시간 : " .. currentTime.hour)
   
    secondHandimg.rotation = currentTime.sec * (360/60)
    minuteHandimg.rotation = currentTime.min * (360/60)  + (currentTime.sec * (360/60)/60)
    hourHandimg.rotation = currentTime.hour * (360/12) + (currentTime.min * (360/12)/60)  + (currentTime.sec * (360/12)/60/60)
end 

-- 현재 시간 표시
dispTime = display.newText( "", 0, 40, native.systemFontBold, 24)
dispTime:setFillColor( 1/255,120/255,120/255)
dispTime.anchorX = 0.5
dispTime.x = __appContentWidth__ * 0.5

-- 시간 업데이트 시작
updateCLock()
timer.performWithDelay(1000, updateCLock, 0)

디자인: 김성우님

매거진의 이전글 국내 최초 코로나 SDK 세미나 영상
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari