Skip to content

AnimationZoneDemo.lua

xu.jingyu edited this page Dec 24, 2019 · 4 revisions

AnimationZone

copy下面代码,运行试试

local screenSize = System:screenSize()
local screen_w = screenSize:width()
local screen_h = screenSize:height()

az = AnimationZone()
az:width(screen_w):height(screen_h -64):marginTop(64)
az:bgColor(Color(128,21,23,1))

animationView = View()
animationView:bgColor(Color(255,0,0,1))
animationView:width(80):height(80):marginTop(64)

az:addView(animationView)

isAnimating = false
animation_t = FrameAnimation()
animation_t:setEndCallback(function()
    print("|| Translate end!")
    isAnimating = false
end)

function dotTranslate()
    animation_t:setTranslateXTo(300)
    animation_t:setDuration(10)
    animation_t:setInterpolator(InterpolatorType.AccelerateDecelerate)
    animation_t:start(animationView)
end

animation_s = Animation()
function dotScale()
    animation_s:setScaleX(0.5, 1.2)
    animation_s:setScaleY(0.5, 1.2)
    animation_s:setDuration(2)
    animation_s:setInterpolator(InterpolatorType.Bounce)
    animation_s:start(animationView)
end

animationView:onClick(function()
    print("|| Animation Click!")
    if isAnimating then
        dotScale()
    else
        dotTranslate()
        isAnimating = true
    end
end)

window:addView(az)
Clone this wiki locally