A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: scripted movement over time period/frame length

  1. #1
    con[fuzed] designer
    Join Date
    Jan 2003
    Location
    UK
    Posts
    314

    scripted movement over time period/frame length

    i'm using this as to move an mc across the screen on the x coordinate:

    code:

    onClipEvent (load) {
    //set initial x pos of clip
    this._x = 0;
    }

    onClipEvent(enterFrame){
    //this moves our clip 1 pixel to the right every frame
    //up to a certain point
    if (this._x<300)
    {
    this._x+=1;
    }
    }



    I need to adjust this so that the movement takes place over an alotted time period or a defined frame length. Any ideas?

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Try this. Nice movement with easing.


    onClipEvent (load) {
    //set initial x pos of clip
    this._x = 0;
    // How fast will it move
    speed=5;
    // Where should it go
    destination=500;
    }
    onClipEvent(enterFrame){
    this._x+=(destination-this._x)/speed;
    }

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  3. #3
    con[fuzed] designer
    Join Date
    Jan 2003
    Location
    UK
    Posts
    314
    thanks man but you show me how it would be done without the easing becuase it is for the movement of an animal and needs to be a consistent speed.

  4. #4
    con[fuzed] designer
    Join Date
    Jan 2003
    Location
    UK
    Posts
    314
    most important really is the ability to control the movement so that it can move extremely slowly even though the movie that contains it (its an external swf loaded into a container movie) is playing at 50fps.

  5. #5
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Then its better with your way but having something like...

    if (this._x<300)
    {
    this._x+=0.2;
    }

    ........to have it move really slowly.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  6. #6
    con[fuzed] designer
    Join Date
    Jan 2003
    Location
    UK
    Posts
    314
    thanks, when the mc reaches this point i want it to replay from x_= 0 after a delay. I was thinking of using setInterval for this, how would be the best way to implement this?

    Cheers.

  7. #7
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Im not familiar with set interval. I would do like this.....

    if(this._x == 300){
    wait+=1;
    // Wait 100 frames before resetting things
    if(wait>100){
    //Reset actions here
    wait=1;
    }
    }

    ..simply add this to your code.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  8. #8
    con[fuzed] designer
    Join Date
    Jan 2003
    Location
    UK
    Posts
    314
    mmm... not quite workin, the mc stops at the _x = 500 point but does not start again.

    This is what i got:

    code:

    onClipEvent (load) {
    //set initial x pos of clip
    this._x = 0;
    }

    onClipEvent(enterFrame){
    //this moves our clip 1 pixel to the right every frame
    //up to a certain point
    if (this._x<500)
    {
    this._x+=0.5;
    }
    if(this._x == 500){
    wait+=1;
    // Wait 100 frames before resetting things
    if(wait>100){
    //Reset actions here
    wait=1;
    }
    }

    }



  9. #9
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    You ahve not specified what is going to happen when it reaches x 500. Where I wrote..........

    //Reset actions here

    That where you put.......

    this._x=0;

    ....or whatever action you need to happen there.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  10. #10
    con[fuzed] designer
    Join Date
    Jan 2003
    Location
    UK
    Posts
    314
    my bad, sorry man.

    Thanks for all the help.

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