Snow Graphics

Hey Guys!
So, I've got another question.... I'm trying to make some snow fall and the snow is deleting as soon as it appears... It's proably something simple!

Anyway Here's the code!
~Caleb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function makesnow()
                local snowfall= display.newCircle(240,200,4)
                mastergroup:insert(snowfall)
                snowfall:setFillColor(210,210,210)
 
                snowfall.y= 200--20
                snowfall.x= math.random(0,340)
                
                function snowfall:enterFrame(event)
                self.x= math.random(0,340)
 
                        self.y= 200
                        self.life=10
                        self.life= self.life-.1
                                                print(self.life)
                        if (self.life == 0) then
                                Runtime:removeEventListener("enterFrame",self);
                                self:removeSelf();
                        end
 
        end
                                Runtime:addEventListener("enterFrame",snowfall)
end

The snow deletes immediately because there is nothing stopping line 14 from counting right the way down to 0 as fast as the device can manage.

Try calling the "self.life = self.life - .1" line inside a function, and then call the function with a timer set to trigger every x milliseconds.

Does that help? If it doesn't make sense let me know and I'll work something up when I can.

Thanks! I'm not sure what you mean.. It's a litle confusing. (well I am cofused... everyone else probably gets it :P) Anyway.. how do I know what particle (or "snowfall") I am doing "self.life" for in another function? Because I have multiple EventListeners, for each "snowfall". So how do I want to make it recognize what "snowfall"'s life I am tweaking?
Thanks for the help!

You can look at particle engines if that helps, it's all the work already done for you, plus JStrahan has a really nice library which he will release soon, see his awesome rain demo.

cheers,

?:)

Ok, I'll look at that....!

Me and my uncle got it! I was only calling Makesnow() once... I had some other things wrong with its too... Thanks so much!

views:1571 update:2011/10/19 14:58:09
corona forums © 2003-2011