Problems with timer

So I’m learning programming and trying to create a simple game for the start.

My game (yet) is: balloon is flying from bottom to top and when you click the balloon it bursts.

But after balloon explodes I want to make appear an image that looks similar to exploded firework or something like that. I want to do this to make explosion look more lively and realistic.

I can make timer work when I type this at the bottom of my code.

timer.performWithDelay( 500, destroy\_blurp, 1)  

^This code says to destroy ‘blurp’ (that’s how I called the fireworks-explosion image) image after half of a second

This way timer starts counting when the app is launched. That’s not what I want. I want that timer would start counting after I click the balloon.

Then I tried this code. And now timer doesn’t work at all:

local function destroy( event )  
if event.phase == "ended"  
then timer.performWithDelay( 500, destroy\_blurp, 1)  
balloon\_blue.isVisible = false  
end  
end  
  
balloon\_blue:addEventListener( "touch", destroy )  

^This way I want to say that when I click balloon it disappears and also timer starts counting so that ‘blurp’ image would gone after half of a second. But ‘blurp’ image just stays.

So what’s my problem? [import]uid: 46567 topic_id: 10049 reply_id: 310049[/import]

Do you mean you want the blurp effect to fade in then fade out?

The issue lies in your blurp function. Try this

[lua]

local blurp = function (x,y)
local effect = display.newImageRect(“example.png”, 70,70)
effect.x = x
effect.y = y
effect.alpha = 0

if effectTween then transition.cancel(effectTween) end

local removeEffect = function(obj)
obj:removeSelf()
end

local fadeEffect = function ()
local fadeTween = transition.to(effect,{time=500, alpha = 0, onComplete = removeEffect})
end

local effectTween = transition.to(effect,{time=500, alpha = 0, onComplete = fadeEffect})
end
– in your collision, just call this
local onCollide = function (self, event)
if event.phase == “ended” then
– call your effect
blurp(self.x,self.y)
end
end
[import]uid: 12455 topic_id: 10049 reply_id: 36735[/import]

I don’t understand almost anything that you wrote here. As I sad I’m new at Corona (as well as programming).

But I tried to play with transitions by myself and I got it working! Exactly as I wanted :slight_smile:
I just made this simple function with transition.from:

local function destroy\_blurp( event )  
blurp\_i.alpha = 0  
transition.from ( blurp\_i, {time=100, alpha=1} )  
end  
  
balloon\_blue:addEventListener( "touch", destroy\_blurp )  

Still thanks a lot for idea to use transitions instead of timer, now I can continue learning! [import]uid: 46567 topic_id: 10049 reply_id: 37177[/import]

So I got into some small problem again. I though I would better not create a new thread as my question is simple as hell (at least for most of you)

So in my simple game, where balloon flies from bottom to top and you need to destroy it, I want to add a function that would show you “game over” image when balloon reaches the top of the screen. So this is the function that I’ve created with my “logic” brains.

local function gameOver( event )  
if balloon\_blue.y == 1  
then game\_over.isVisible = true  
end  
end  

^By coding this I wanted to say that if balloon reaches the top (1 is first screen’s pixel), then “game over” image appears. But it doesn’t work.

As I said I’m total newbie (or noobie) at programming and I can understand only some simple coding. So I would be thankful if someone would explain what’s wrong with my stupid function or suggest some SIMPLE alternative. [import]uid: 46567 topic_id: 10049 reply_id: 37327[/import]

Do you have code to remove the “blurp” image? You removed the balloon by doing this:

balloon\_blue.isVisible = false  

But do you have anything similar to remove the blurp as well? You haven’t posted what’s in your destroy_blurp function [import]uid: 31262 topic_id: 10049 reply_id: 37333[/import]

Hi, aaaron, I don’t have problems with blurp anymore, I wrote that in 3rd post by saying “But I tried to play with transitions by myself and I got it working! Exactly as I wanted :)”

Now I’m having problem with other function (see 4th post). You probably missed that.

I know it’s not connected with timer anyhow, but I just thought it’s not worth to create a new thread for such a simple question :slight_smile: [import]uid: 46567 topic_id: 10049 reply_id: 37335[/import]