A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: skipping frames - flash game

  1. #1
    Member
    Join Date
    Mar 2002
    Posts
    68

    skipping frames - flash game

    Hello people...

    I'm creating a game where I need the speed of certain movie clips to speed up or slow down depending on what the player collides with or picks up. To do this I altered the value of a variable 'n' on collision etc... and then used the following script in the timeline:

    if (n+_currentframe<=40) {
    gotoAndPlay(_currentframe+n);
    }
    if (n+_currentframe>40) {
    gotoAndPlay((_currentframe+n)-40);
    }

    I've used the IF statement as my MC is a 40 frame loop so need the clip to jump to the corresponding frame at the start of the loop if _currentframe+n is greater than 40.

    THE PROBLEM is that this code causes flash problems (i get the dialogue box 'A script in your movie is causing flash to run slow - abort script?). I've tried using the script in 2 ways: in a key frame on every frame of my 40 frame MC and in a separate 2 frame MC with the code in the first frame and a goto in the 2nd frame (and inserting _root where appropriate). Whichever way I try I get the same problem...

    Any suggestions very welcome as I'm getting a headache now...

    thanks p. melons

  2. #2
    Senior Member
    Join Date
    Apr 2001
    Location
    UK
    Posts
    493
    is each movieclip and animation?
    If so why not move each with a actionscript, and use a global or local speed value to change the rate of motion?

    Not sure exactly how you have your movie setup but with the code you have, the movie would get stuck in a loop and execute multiple scripts, basically causing an inifinite loop as in an incorrectly written for or while script.

  3. #3
    Member
    Join Date
    Mar 2002
    Posts
    68
    I could switch some of my animations to work as MCs controlled by the speed variable BUT there is also some shape tweening going on so I need to figure this skipping frame thing out.

    out of interest, what do I need to do to make speed local to one clip or global so all clips can read it?

    cheers, pm

  4. #4
    Senior Member
    Join Date
    Apr 2001
    Location
    UK
    Posts
    493
    various ways to do the global speed rather than local. Obviously local would be contained script within the MC.

    option1:

    set _root.Speed variable and use this within internal script of MovieCLip. All instances will look on root for the value

    option2:

    MovieClip.prototype.Speed=3
    This adds a speed variable to the MovieClip class, thus all movieclips will have a .Speed, just reference as this.Speed from within the movieclip


    As for your frames problem, coudl you post stripped down example ?
    Have to see what you have to come up with a fix/work around.

  5. #5
    Member
    Join Date
    Mar 2002
    Posts
    68
    cheers for the reply - source file can be found at:

    http://www.pdggraphics.com/fk/for_fk.fla

    i created this just to demonstrate the problem and left in the dodgy actions so you can see the thing go wrong. the buttons just alter the value of 'n'.

    thanks pm

  6. #6
    Member
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    38
    Hi,

    I can see that you are using php as well as flash and sql. I have the same issue but not in the same context.
    Could you please tell me how to set a flash background into a php page using sql data.

    Thanks,

    Sebastien

    You can e-mail me at the following: catandseb@hotmail.com
    Seb

  7. #7
    Member
    Join Date
    Mar 2002
    Posts
    68
    i take it you didn't mean to post that message there? can't help you with that one i'm afraid...

    pm

  8. #8
    Senior Member
    Join Date
    Apr 2001
    Location
    UK
    Posts
    493
    OK got a work around, One which may be a bit processer intensive on slower machine. However its not a bad example of how to modify the internal frame speed of a movie.

    The other is a simple fix


    Option1:
    All code
    set variable fps ( frames per second) and create an interval on 1000/fps, which gives you a time between each frame
    got to next frame after this time.
    Update the FPS in each button and reset interval.


    Option2:
    (attached next post)
    Duplicate the animation and place linear on timeline. Calculate the relevent frame to go to with the faster or slower animation.


    hope these help. Any questions let me know
    Attached Files Attached Files

  9. #9
    Senior Member
    Join Date
    Apr 2001
    Location
    UK
    Posts
    493
    Option 2
    Attached Files Attached Files

  10. #10
    Member
    Join Date
    Mar 2002
    Posts
    68
    thanks, I think i'll go with option 2 to avoid affecting game play.
    anychance you could post the code with a little comment so i can work out excatly what's going on...?

    cheers anyaway, pm

  11. #11
    Senior Member
    Join Date
    Apr 2001
    Location
    UK
    Posts
    493
    Sure sorry forgot ot add it first time

    sPoints=[1,31,46] //start frames of each speeed section

    anim=0 // reference to sPoints, indicates current animation
    factor=2 // how much quicker or slower each speed section is i.e x2 1st animation=30 frames 2nd=15


    //function to determine gotoFrame
    function getNewFrame(newAnim)
    {
    //newAnim if passed from the buttons indicates next index in sPoints

    newFrame=_currentframe-sPoints[anim] //get frame in relation to start point
    if(newAnim>anim)
    {
    //if > need to divide as gets slower
    //if you break this down it means
    // if going from animation 1(anim) to 2(newAnim) and on frame 8 of animation 1
    // 8/((2-1)*2)=4
    //where the 8th frame in the first animation equates to the 4th in the next as is 1/2 the frame number (x2)
    //hope that makes sense!
    newFrame=Math.floor(newframe/((newAnim-Anim)*factor))
    }else{
    //if < need to Muliply as quicker
    newFrame=Math.floor(newframe*((newAnim-Anim)*factor))
    }
    //set to new anim
    anim=newAnim
    trace(newFrame)
    gotoAndPlay(newFrame)
    }

    hpe that makes sense!?

  12. #12
    Member
    Join Date
    Mar 2002
    Posts
    68
    thanks a lot for your help.

    pm

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