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( )
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
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]
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.
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.
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
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]