Random egg

hi
i am having 15 eggs ovet the top of screen , and they used to fall randomly, when they collide with the ground they disapper after some time
and again falling of egg form top continues…

How to do it in effective way

I understand your problem, but I don’t understand what an “effective” way would be/

Umm the effective way is to have 15 eggs, and on collision with ground, just make em jump at a random spawn point on the top

Just subtract a random value from the Y attribute when the egg is destroyed. Note that this value must be within a predefined range and must not be smaller than Stage.height. If you need any help with the coding, just let me know, but, judging by your posts here, you know how to do that. :wink:

well it will be nice if you can send some code

acutally i want to write a class that is applicable to all eggs and some using inheritance concept …

If you send us the file, I can make it work. :slight_smile: With comments so you know how to modify it to your specific needs.

try

var ySpeed:Number;
var myRoot:MovieClip = this;
function ymove() {
 this._y += this.ySpeed;
 if (this.hitTest(ground_mc)) {
  this.removeMovieClip();
  attachEgg();
 }
}
function attachEgg() {
 ySpeed = Math.ceil((Math.random()*4)+2);
 var mc:MovieClip = myRoot.attachMovie("egg", "egg"+myRoot.getNextHighestDepth(), myRoot.getNextHighestDepth());
 mc._y = -60;
 mc._x = Math.floor(Math.random()*(Stage.width-mc._width));
 mc.ySpeed = ySpeed;
 mc.onEnterFrame = ymove;
}
for (i=0; i<15; i++) {
 attachEgg();
}

[quote=neilmmm;2331376]try

var ySpeed:Number;
var myRoot:MovieClip = this;
function ymove() {
 this._y += this.ySpeed;
 if (this.hitTest(ground_mc)) {
  this.removeMovieClip();
  attachEgg();
 }
}
function attachEgg() {
 ySpeed = Math.ceil((Math.random()*4)+2);
 var mc:MovieClip = myRoot.attachMovie("egg", "egg"+myRoot.getNextHighestDepth(), myRoot.getNextHighestDepth());
 mc._y = -60;
 mc._x = Math.floor(Math.random()*(Stage.width-mc._width));
 mc.ySpeed = ySpeed;
 mc.onEnterFrame = ymove;
}
for (i=0; i<15; i++) {
 attachEgg();
}

[/quote]

Thanks for your Fla…this is what i was looking for …

yw

Just a comment. If you intend to have a variable falling interval, so the eggs don’t always fall the exactly ammount of time after they collide with the ground, set the _y to a random value below 0, instead of a fixed -60. =)

Something like:

_y = -(mc._height + Math.floor(Math.random()*range));

Where range is the _y value range.

each egg has a unique ymove variable attached to it … so when they fall they fall at different speeds onEnterframe not on a setInterval

ySpeed = Math.ceil((Math.random()*4)+2);

and

this._y += this.ySpeed;

the this.ySpeed is referencing

this egg’s ySpeed which is different to the next egg’s ySpeed

does this make sense?

I wasn’t talking about the speed… The point is, if when they fall and are destroyed their y is set to -60 everytime, the interval between the destruction of the egg and it’s reappearance is always the same, no matter how long it will take to fall from the place it appears to the bottom of the screen (which is what is controlled by the random speed).

In a very optimistic view, they will be slightly different because of the time each egg will take to move those 60 off-screen pixels, which may delay or accelerate it’s actual appearance on screen. But it won’t be too much of a difference anyway.