A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Math: Total Distance according to Speed and Time

  1. #1
    Junior Member
    Join Date
    Sep 2002
    Posts
    22

    Math: Total Distance according to Speed and Time

    // Fort Canning Park Walkthrough : final semster project 2002
    // user speed input
    if (_root.input.text == "") {
    speed = 1;
    } else {
    speed = _root.input.text;
    //trace(speed);
    }
    // forward and rewind of mc
    mcscene5.onEnterFrame = function() {
    mousePos = _root._ymouse;
    cfrm = _root.mcscene5._currentframe;
    if (mousePos>0 && mousePos<175) {
    _root.mcscene5.gotoAndStop(cfrm+speed/1);
    } else if (mousePos>225 && mousePos<400) {
    _root.mcscene5.gotoAndStop(cfrm-speed/1);
    }
    };
    updateAfterEvent;
    // Time
    timevar = Math.round((getTimer()/1000));
    tfrm = _root.mcscene5._totalframes;
    // Distance
    function distance() {
    x = (Math.round((getTimer()/1000)*speed/6));
    trace(x);
    distvar = ++x;
    updateAfterEvent;
    }

    if (mousePos>0 && mousePos<175 && cfrm>9 && cfrm<(tfrm-9)) {
    distance();
    } else if (mousePos>225 && mousePos<400 && cfrm>9 && cfrm<(tfrm-9)) {
    distance();
    }

    The problem are those in bold text. My current does dosen't work. I want to work out the total distance travel taking into account the speed input by the user and the time. I only want the ticking of the time ( for the distance ) to start when the user is forwarding. And that the ticking of the distance meter will be faster when they put in a faster speed... slower when they put a smaller speed. My current method just dosen't work out so hopefully some Math guru can help me out here and give me a solution or just some hints to guide me? Thank you.

  2. #2
    Junior Member
    Join Date
    Sep 2002
    Posts
    22
    any ideas? please do help. I really need to finish this script before i can continue with anything else.
    here's the source file if you don't know what i mean.
    Last edited by Ling Nightsky; 10-27-2002 at 12:50 PM.

  3. #3
    Junior Member
    Join Date
    Sep 2002
    Posts
    22
    anyone please? i'm going out of my mind.

  4. #4
    Junior Member
    Join Date
    Sep 2002
    Posts
    22
    nvm, i finally figured it out after banging my head against the wall.

    function distance() {
    speedvar = Math.round(speed+1);
    speedvar1 = Math.round(speedvar/10);
    distvar1 = Math.round(distvar1+speedvar1);
    distvar = Math.round(distvar1/20);
    }

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center