Professional Web Applications Themes

Bouncing Ball... Help - Macromedia Flash Sitedesign

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) ...

  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. #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

  3. #3

    Default Re: Bouncing Ball... Help


    "tralfaz" <tralfazmxyahoo.cam> wrote in message
    news:buig46$1ge$1forums.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

  4. #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

Similar Threads

  1. Age old table bouncing question
    By Nicholas M in forum Macromedia Dynamic HTML
    Replies: 3
    Last Post: September 18th, 10:33 AM
  2. Bouncing mail
    By RAJA. M in forum Coldfusion - Getting Started
    Replies: 1
    Last Post: October 27th, 07:16 PM
  3. Bouncing mails
    By Owen in forum PERL Beginners
    Replies: 1
    Last Post: February 6th, 08:19 AM
  4. bouncing ball
    By Joso webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: February 2nd, 09:14 PM
  5. bouncing objects
    By Ya Ma in forum Macromedia Flash
    Replies: 1
    Last Post: July 11th, 12:47 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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