Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added blinkContinuous function #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion transition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ function lib:enterFrame ( event )
end
else
-- the easing function easing.continuousLoop with infinite iterations cannot set the object keys to the finish values.
-- also, the last iteration of a transition with easing.continousLoop has to return the object to the start properties,
-- also, the last iteration of a transition with easing.continuousLoop has to return the object to the start properties,
-- not to the end ones.
if tween._transition == easing.continuousLoop or tween._isLoop then
if tween.iterations == 1 then
Expand Down Expand Up @@ -859,6 +859,51 @@ lib.blink = function( targetObject, params )

end

-----------------------------------------------------------------------------------------
-- blinkContinuous( targetObject, actionDuration )
-- blinks the targetObject with the transition duration actionDuration with continuous alpha-channel changes
-----------------------------------------------------------------------------------------
lib.blinkContinuous = function( targetObject, params )
if targetObject == nil then
if lib.debugEnabled then
error( DEBUG_STRING .. " you have to pass a target object to a transition.blinkContinuous call." )
end
end

local paramsTable = params or {}

local actionTime = paramsTable.time or 500
local actionDelay = paramsTable.delay or 0
local actionEasing = paramsTable.transition or easing.linear
local actionOnComplete = paramsTable.onComplete or nil
local actionOnPause = paramsTable.onPause or nil
local actionOnResume = paramsTable.onResume or nil
local actionOnCancel = paramsTable.onCancel or nil
local actionOnStart = paramsTable.onStart or nil
local actionOnRepeat = paramsTable.onRepeat or nil
local actionTag = paramsTable.tag or nil
local actionTime = actionTime or 500

local addedTransition = lib.to( targetObject,
{
delay = actionDelay,
time = actionTime * 0.5,
transition = easing.continuousLoop,
iterations = -1,
onComplete = actionOnComplete,
onPause = actionOnPause,
onResume = actionOnResume,
onCancel = actionOnCancel,
onStart = actionOnStart,
onRepeat = actionOnRepeat,
alpha = 0,
tag = actionTag
} )

return addedTransition

end

-----------------------------------------------------------------------------------------
-- moveTo( targetObject, xCoord, yCoord, actionTime, actionDelay )
-- moves the targetObject to the xCoord, yCoord coordinates with the transition duration actionDuration and delay actionDelay
Expand Down
8 changes: 8 additions & 0 deletions unit_test/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ r2:setFillColor( 0, 255, 0)
r1.onComplete = onComplete
r2.onComplete = onComplete

local r3 = display.newRect( 1, 2*h, w, h )
r3:setFillColor( 0, 0, 255 )
transitionNew.blink( r3, { time = 3000 } )

local r4 = display.newRect( 2 * w, 2 * h, w, h )
r4:setFillColor( 0, 0, 255 )
transitionNew.blinkContinuous( r4, { time = 3000 } )

function touchHandler (event)
if (event.phase == "began") then
transitionNew.cancel( event.target.t )
Expand Down