Results 1 to 12 of 12

Thread: random egg

  1. #1

    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

  2. #2
    I understand your problem, but I don't understand what an "effective" way would be/

  3. #3
    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
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  4. #4
    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.
    Bruno Palermo
    When everything is catastrophic, thank the Gods things aren't worse!

  5. #5
    Quote Originally Posted by bpalermo View Post
    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.
    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 ......
    Last edited by rahul_7star; May 24th, 2008 at 03:19 AM.

  6. #6
    If you send us the file, I can make it work. With comments so you know how to modify it to your specific needs.
    Bruno Palermo
    When everything is catastrophic, thank the Gods things aren't worse!

  7. #7
    try
    Code:
    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();
    }
    Attached Files Attached Files

  8. #8
    Quote Originally Posted by neilmmm View Post
    try
    Code:
    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();
    }
    Thanks for your Fla.....this is what i was looking for ...

  9. #9
    yw

  10. #10
    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:
    Code:
    _y = -(mc._height + Math.floor(Math.random()*range));
    Where range is the _y value range.
    Last edited by bpalermo; May 30th, 2008 at 02:50 PM.
    Bruno Palermo
    When everything is catastrophic, thank the Gods things aren't worse!

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

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


    Code:
    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?

  12. #12
    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.
    Last edited by bpalermo; May 31st, 2008 at 11:06 AM.
    Bruno Palermo
    When everything is catastrophic, thank the Gods things aren't worse!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012