Bouncing Ball... Help

Ask a Question related to Macromedia Flash Sitedesign, Design and Development.

  1. #1

    Default Bouncing Ball... Help

    I used to have a problem controling a ball with the key up, then someone
    gave me the following script to resolve the problem (thank's TRALFAZ) :

    onLoad = function() {
    dir = -1; // up
    inMotion = 0;
    }

    // move ball from 350 y to 150 y when key up is pressed
    onEnterFrame = function() {
    // up key only works when ball is not in motion
    if(!inMotion && Key.isDown(Key.UP))
    inMotion = 1;

    if(inMotion)
    {
    // simulated gravity.
    // slow down when approaching apex at 150
    // minimum speed is 2
    speed = 2 + (ball._y - 150) * .3;

    ball._y += (speed * dir);
    if(ball._y <= 150) // at the apex, change direction
    {
    dir = 1; // change direction to down
    }
    else if(ball._y >= 350) // at the bottom, stop (should bounce)
    {
    inMotion = 0; // stop motion
    dir = -1; // changed direction to up
    }
    }
    }

    ....and it did, but now i can't make the ball land in the same _y twice, as I
    inteded ( it should always land on _y = 250)...
    can someone please help me...


    much appreciated



    zecka3 Guest

  2. Similar Questions and Discussions

    1. Age old table bouncing question
      Hi, I started designing in CSS a few months back after doing it in tables for a few years. Recently got a request to update a site for a friend...
    2. Bouncing mail
      How can i get the bouncing mail ids from the coldfusion log file? let me know whether the incoming and outgoing details will be there? Thanks in...
    3. Bouncing mails
      Al Kaibala DO YOU READ THIS? List members, As administrator of the Linux SIG List, I am getting bounces for mail addressed to kabalg@localhost...
    4. bouncing ball
      hi, if you check out this link : http://www.atreyuonline.com/flash/gravity.html You will see i've got a bouncing ball and a red bar across...
    5. bouncing objects
      Im looking for a good tutorial for making bouncing objects with colisions, does anyone know a good one ?
  3. #2

    Default Re: Bouncing Ball... Help

    > ...and it did, but now i can't make the ball land in the same _y twice, as
    I
    > inteded ( it should always land on _y = 250)...
    > can someone please help me...
    The example code made the object bounce up from 350y up to 150y and back
    down to 350y. If you want the bottom at 250, just change all the 350s to
    250s. You can set the 150s to a smaller number if you want the ball to move
    higher.
    good luck,
    tf


    tralfaz Guest

  4. #3

    Default Re: Bouncing Ball... Help


    "tralfaz" <tralfazmx@yahoo.cam> wrote in message
    news:buig46$1ge$1@forums.macromedia.com...
    >
    > > ...and it did, but now i can't make the ball land in the same _y twice,
    as
    > I
    > > inteded ( it should always land on _y = 250)...
    > > can someone please help me...
    >
    > The example code made the object bounce up from 350y up to 150y and back
    > down to 350y. If you want the bottom at 250, just change all the 350s to
    > 250s. You can set the 150s to a smaller number if you want the ball to
    move
    > higher.
    > good luck,
    > tf
    >
    I'm sorry for trouble you but, the thing is that the freeking ball
    doesn't land in the same _y pos twice , it keeps on changing if you don't
    mind i put an example here [url]http://jdf.planetaclix.pt/exp.html[/url] if you could
    take a look to it I´d appreciated.

    Thank´s


    zecka3 Guest

  5. #4

    Default Re: Bouncing Ball... Help

    When the movieclip is rotating it affects the _Y value if the registration
    point is not exactly in the center. If you can't easily fix that, you could
    try using a variable to track the y position like this:

    onLoad = function() {
    dir = -1; // up
    pos = 300; // position tracking variable
    }

    // move ball from 300 y to 150 y when key up is pressed
    onEnterFrame = function() {
    // up key only works when ball is not in motion
    if(!inMotion && Key.isDown(Key.UP))
    inMotion = 1;

    if(inMotion)
    {
    // simulated gravity.
    // slow down when approaching apex at 150
    // minimum speed is 2
    speed = 2 + (ball._y - 150) * .3;
    pos += (speed * dir); // update the tracking var
    ball._y = pos; // make the clip the same as pos
    if(pos <= 150)
    {
    dir = 1; // change direction to down
    }
    else if(pos >= 300) // check the var instead of the clip
    {
    ball._y = pos; // force the clip to position 300
    inMotion = 0; // stop motion
    dir = -1; // changed direction to up
    }
    }
    }

    I hope that will do it for ya,
    tf
    > I'm sorry for trouble you but, the thing is that the freeking ball
    > doesn't land in the same _y pos twice , it keeps on changing if you
    don't
    > mind i put an example here [url]http://jdf.planetaclix.pt/exp.html[/url] if you could
    > take a look to it I´d appreciated.
    >
    > Thank´s

    tralfaz Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139