-
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?
-
Senior Member
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;
}
-
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.
-
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.
-
Senior Member
Then its better with your way but having something like...
if (this._x<300)
{
this._x+=0.2;
}
........to have it move really slowly.
-
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.
-
Senior Member
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.
-
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;
}
}
}
-
Senior Member
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|