Continuous transition

Hi the people :wink:

Is there a way to have a continuous transition.to ?
For example, I would like to have an image continuously fading in and out by using transition.to on its alpha.

Any idea ?

Patrick [import]uid: 47196 topic_id: 9284 reply_id: 309284[/import]

This example should do it:

http://developer.anscamobile.com/reference/index/transitionto

[import]uid: 295 topic_id: 9284 reply_id: 33871[/import]

local specialButton = display.newImage(ā€œbuttonBlue.pngā€)
specialButton.alpha = 0.6
specialButton.x = 240
specialButton.y = 280
localGroup:insert(specialButton)

function myff1()
t2 = transition.to( specialButton,{alpha = 1, onComplete = myff2})
end

function myff2()
t1 = transition.to( specialButton,{alpha = 0, onComplete = myff1})
end
myff2() [import]uid: 12482 topic_id: 9284 reply_id: 33886[/import]

hgvyas123 - see lot of code posted by you on the forum… suggest you to start using lua tags to post code… makes it more readable…

[lua]local specialButton = display.newImage(ā€œbuttonBlue.pngā€)
specialButton.alpha = 0.6
specialButton.x = 240
specialButton.y = 280
localGroup:insert(specialButton)

function myff1()
t2 = transition.to( specialButton,{alpha = 1, onComplete = myff2})
end

function myff2()
t1 = transition.to( specialButton,{alpha = 0, onComplete = myff1})
end
myff2()[/lua] [import]uid: 48521 topic_id: 9284 reply_id: 33905[/import]

great doesn’t know about [lua][/lua] tag thanks [import]uid: 12482 topic_id: 9284 reply_id: 33909[/import]

Thanks for your answers, but :

@tokyodan : nope. That example just does two transitions and then stops. I want the image to continuously fade in and out.

@hgvyas123 : this is exactly what I tried to do. But i doesn’t work. The image fades out, then back in and then stops changing. The functions are not recursively called.

Any other idea ?
Patrick [import]uid: 47196 topic_id: 9284 reply_id: 33911[/import]

works perfectly with me

tested on corona simulator and xcode simulator

[lua]module(…, package.seeall)

function new()
local localGroup = display.newGroup()
local specialButton = display.newImage(ā€œbuttonBlue.pngā€)
specialButton.alpha = 0.6
specialButton.x = 240
specialButton.y = 280
localGroup:insert(specialButton)

function myff1()
t2 = transition.to(specialButton,{alpha = 1, onComplete = myff2})
end

function myff2()
t1 = transition.to(specialButton,{alpha = 0, onComplete = myff1})
end
myff2()
return localGroup
end[/lua]

i am using director class [import]uid: 12482 topic_id: 9284 reply_id: 33912[/import]

I had almost the same code as yours and mine didn’t work!
Then I saw the difference : my functions where declared as local, not yours.
I removed ā€œlocalā€ and then it works!
I can’t really understand what is going on there.
Can you explain ?
Thanks
Patrick [import]uid: 47196 topic_id: 9284 reply_id: 33915[/import]

ok local means for that particular file only and if you don’t put local then it is global

when you declare function as local it is necessary that your function should be above your line of code through which you are calling and it is not necessary for the global function

chheers [import]uid: 12482 topic_id: 9284 reply_id: 33919[/import]

Ok, thank you for your help.
Patrick [import]uid: 47196 topic_id: 9284 reply_id: 33941[/import]

another the way:

Note: I haven’t tested this code
[lua]if image1Tran then transition.cancel(image1Tran) end

local function animeFade ()

local fadeBack = function ()
transition.to(image1, {time = 1000, alpha = 1, onComplete = animeFade})
end
local image1Tran = transition.to(image1, {time = 1000, alpha = 0, onComplete = fadeBack})
end

animeFade() [import]uid: 12455 topic_id: 9284 reply_id: 33944[/import]