-
Delay for loop Help
I ve done simple dripping effect, but I need those drops to have some delay between their droping, lets say 2 sec..
Heres the code:
Actionscript Code:
var nDrop:uint = 1; var dripping:Drop = new Drop();
function init(){ setD(); } function setD():void{ addChild(dripping); dripping.ySpeed = 35 + Math.random() * 5; dripping.cacheAsBitmap = true; addEventListener(Event.ENTER_FRAME, drip, false, 0, true); } function drip(event:Event):void {
for (var i = 0; i < nDrop; i++) {
dripping.y += dripping.ySpeed;
if (dripping.y > 500 + Math.random() * 450) { dripping.x = Math.random() * 790; dripping.y = Math.random() * -1000;// Here, I ve moved startingY point to way off stage //to simulate delay.. } } } init();
I cant get it right..help..
Thnx
-
You only have a single drop, so why do you have an nDrop variable, as if you had a collection of drops. If you plan to make a bunch of drops later, then you should put your single drop into a collection anyway so you can loop over that collection.
You can remove the drip listener when the drop falls off the screen, and set a timer with a listener to re-initialize it. But when or if you decide to make more drops, you'll want to rethink that since you'll still have some drops falling when one is ready to be removed.
-
Yes, I started with few drops, but decided to stick to one, changing random entries of it..forgot to discard uint.. I did change to TimerEvent, but then I loose the speed of drop, dripping.ySpeed.. How could I set the Timer delay to 2000, and stil having the speed of drop as it is on ENTER_FRAME example above? I repeat, I need delay, something that does the trick exactly like that cheat-delay I did in which drop consumes some time before it appears on stage again, traveling from y -1000..Maybe if You run the code, You ll get the idea..
Sorry,Im so new in this..
-
No, I got the idea the first time. Reread my response. I'm not saying get rid of the enterframe entirely. I'm saying temporarily remove it and set a timer to re-add it after a delay.
-
Originally Posted by 5TonsOfFlax
No, I got the idea the first time. Reread my response. I'm not saying get rid of the enterframe entirely. I'm saying temporarily remove it and set a timer to re-add it after a delay.
YES!! WORKS!
Thanks Man!
Actionscript Code:
var myTimer:Timer = new Timer(3000); myTimer.addEventListener(TimerEvent.TIMER, addDrop); myTimer.start(); var dripping:Drop = new Drop(); function addDrop(ev:TimerEvent):void { dripping.ySpeed = 35 + Math.random() * 5; dripping.cacheAsBitmap = true; dripping.addEventListener(Event.ENTER_FRAME, drip, false, 0, true); stage.addChild(dripping); } function drip(e:Event):void {
for (var i = 0; i < 1; i++) {
dripping.y += dripping.ySpeed;
if (dripping.y > 500 + Math.random() * 450) { dripping.x = Math.random() * 790; dripping.y = Math.random() * -5; e.target.removeEventListener(Event.ENTER_FRAME, drip); e.target.parent.removeChild(e.target); } } }
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|