2011년 2월 27일 일요일

easing animation in Corona SDK

easing library를 통해서 함수형 언어의 특징을 잘 흉내내었다.

http://developer.anscamobile.com/content/animation


Manual animation Using transition
local rect = display.newRect(
  0, 0, 100, 100 )
rect:setFillColor(255,255,255)
 
local tMax =1000+system.getTimer()
local function fadeOut(event)
  local t = event.time
  local rect = event.target
  if t < tMax then
    rect.alpha = 1 - t/tMax
  else
    rect.alpha = 0
    -- done, so remove listener
    Runtime:removeEventListener(
         "enterFrame", fadeOut )
  end
end
 
-- Add listener to begin animation
Runtime:addEventListener(
   "enterFrame", fadeOut )
local rect = display.newRect(
  0, 0, 100, 100 )
rect:setFillColor(255,255,255)
 
transition.to(
  rect, {time=1000, alpha=0})


현재의 상태과 이전될 상태간의 interpolation을 easy library가 알아서 해주는 것이다. interrupt가 낄 수 있을 경우에는 cancel을 할 수 있다.

도움이 되셨다면, 광고 클릭을 ㅎㅎ ^^

댓글 없음:

댓글 쓰기