Pulsate using transition.to

Hi. Trying to make a rectangle pulsate (go from bright to dim and repeat forever). I don’t understand functions all that well (or transitions), so wondering why this doesn’t work:

local function pulsate( )  
  
 transition.to( gameTile, {time=500, alpha = 1})  
  
 transition.to( gameTile, {time=500, alpha = .5, onComplete=pulsate})  
  
end  
  
pulsate( )  

Thanks! [import]uid: 25480 topic_id: 7229 reply_id: 307229[/import]

Don’t set two transitions; set only one transition, but choose between them depending on the object’s current state:

[code]
local function pulsate()
if gameTile.alpha == 1 then
transition.to( gameTile, {time=500, alpha = .5, onComplete=pulsate})
else
transition.to( gameTile, {time=500, alpha = 1, onComplete=pulsate})
end
end

pulsate( )
[/code] [import]uid: 12108 topic_id: 7229 reply_id: 25421[/import]

And Bingo was his name-o. Works great, thanks! [import]uid: 25480 topic_id: 7229 reply_id: 25436[/import]

So I left the simulator running for at least fifteen minutes with four tiles pulsating and it brought my computer to its knees. When you do transitions, are they adding memory usage each time? Since I was not creating a new graphic each time, I figured memory would be okay.

Or a better question, how do I make something pulsate without eating up memory and crashing the computer? [import]uid: 25480 topic_id: 7229 reply_id: 25441[/import]

does this work any better?

[lua]local pulsate_on – forward references
local pulsate_off – so functions can see each other

function pulsate_off() – still local due to forward reference
transition.to( gameTile, {time=500, alpha = .5, onComplete=pulsate_on})
end

function pulsate_on() – still local due to forward reference
transition.to( gameTile, {time=500, alpha = 1, onComplete=pulsate_off})
end

pulsate_off()[/lua] [import]uid: 6645 topic_id: 7229 reply_id: 25616[/import]

and to make it reusable

[lua]local pulsate_on – forward references
local pulsate_off – so functions can see each other

– note: the transition passes the item being transitioned
– as the onComplete function parameter

function pulsate_off(obj) – still local due to forward reference
transition.to( obj, {time=500, alpha = .5, onComplete=pulsate_on})
end

function pulsate_on(obj) – still local due to forward reference
transition.to( obj, {time=500, alpha = 1, onComplete=pulsate_off})
end

pulsate_off(gameTile)
pulsate_off(gameTile2)[/lua]
etc

also gjperch… i’m wondering how you were making 4 tiles pulse with your code as it only referred to one gameTile. this could possibly be part of your memory/performance leak, but without seeing your code, I can’t tell.

[import]uid: 6645 topic_id: 7229 reply_id: 25617[/import]

I used the code above and just put four transition.tos in each if-else statement. I will have up to four tiles pulsating at one time (if I can get it to work–I’ll try your suggestion to see if that works for my purpose, THANK YOU for the suggestion). If this works, I’ll add additional code inside the function to kick them out of the loop if they move to a different tile.

Here’s the code that crashed the system:

[code]
local function pulsate( )

if gameTile[t+1].alpha == 1 then
transition.to( gameTile[t+5], {time=500, alpha = .5, onComplete=pulsate})
transition.to( gameTile[t-5], {time=500, alpha = .5, onComplete=pulsate})
transition.to( gameTile[t+1], {time=500, alpha = .5, onComplete=pulsate})
transition.to( gameTile[t-1], {time=500, alpha = .5, onComplete=pulsate})
else
transition.to( gameTile[t+5], {time=500, alpha = 1, onComplete=pulsate})
transition.to( gameTile[t-5], {time=500, alpha = 1, onComplete=pulsate})
transition.to( gameTile[t+1], {time=500, alpha = 1, onComplete=pulsate})
transition.to( gameTile[t-1], {time=500, alpha = 1, onComplete=pulsate})
end

end

pulsate( )
[/code] [import]uid: 25480 topic_id: 7229 reply_id: 25837[/import]

Shoot. The code made the tiles pulsate, but it crashes the simulator within 20 seconds. I have a total of 35 tiles in a table (hence the [t+1] stuff). Thinking I’ll have to try a different approach (it’s a game for small kids, so I want to make it very clear what their movement options are). But it surprises me that it crashes the system. How do others put blinking lights and other continuously animated efx into their code?

Here’s what I used:

[code]
local pulsate_on – forward references
local pulsate_off – so functions can see each other

function pulsate_off( ) – still local due to forward reference
transition.to( obj.gameTile[t+1], {time=500, alpha = .5, onComplete=pulsate_on})
transition.to( obj.gameTile[t-1], {time=500, alpha = .5, onComplete=pulsate_on})
transition.to( obj.gameTile[t+5], {time=500, alpha = .5, onComplete=pulsate_on})
transition.to( obj.gameTile[t-5], {time=500, alpha = .5, onComplete=pulsate_on})
end

function pulsate_on( ) – still local due to forward reference
transition.to( obj.gameTile[t+1], {time=500, alpha = 1, onComplete=pulsate_off})
transition.to( obj.gameTile[t-1], {time=500, alpha = 1, onComplete=pulsate_off})
transition.to( obj.gameTile[t+5], {time=500, alpha = 1, onComplete=pulsate_off})
transition.to( obj.gameTile[t-5], {time=500, alpha = 1, onComplete=pulsate_off})
end

pulsate_off( )
[/code] [import]uid: 25480 topic_id: 7229 reply_id: 25846[/import]

ok…

every transition there is calling a transition on 4 tiles when it completes. ie when the transition on gameTile[t+1] completes it calls the 4 transitions… but also when gameTile[t-1] completes it also calls 4 transitions… etc etc therefore it’s trying to call 4 transitions on the same tile, four times.

use my method.

alternatively only set onComplete on 1 of the 4 tiles in each function. since your timing is the same, it should synchronize ok
[import]uid: 6645 topic_id: 7229 reply_id: 25847[/import]

Thanks, jmp909…

That was the code I was looking for, too! [import]uid: 6084 topic_id: 7229 reply_id: 25863[/import]

Of course (after you pointed it out). Working great. I’ve had it running in the simulator for 30 minutes now with no problems.

Thanks!! [import]uid: 25480 topic_id: 7229 reply_id: 25927[/import]