# A tough one...motion trail problem

**URL:** <https://forum.kirupa.com/t/a-tough-one-motion-trail-problem/243395>\
**Category:** programming\
**Created:** [November 6, 2007, 5:27pm UTC](https://forum.kirupa.com/t/a-tough-one-motion-trail-problem/243395 "2007-11-06T17:27:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ginowhitaker](https://avatars.discourse-cdn.com/v4/letter/g/c6cbf5/32.png) [@ginowhitaker](https://forum.kirupa.com/u/ginowhitaker)\
**Post date:** [November 6, 2007, 5:27pm UTC](https://forum.kirupa.com/t/a-tough-one-motion-trail-problem/243395/1 "2007-11-06T17:27:17Z")

</div>

Here’s the scenario:

A movie clip (starMC) is centered on the stage. A large background is moved using the arrow keys to give the illusion of traveling through space. There’s a movieclip attached to the starMC that uses the bitmapData class for a motion trail.

I did a version where the starMC moves and the motion trail works, but with this version, where the starMC is static and the background moves, I can’t figure out how to simulate a motion trail based on the motion of the background.

Anyone have any suggestions?

Here’s the AS…

\_root.attachMovie(“star”, “starMC”, 10000,{\_x:250,\_y:250});  
\_root.attachMovie(“trail\_sprite”, “trail\_mc”, 8000);

trailbitmap = new flash.display.BitmapData(500, 350, true,0x000000);  
\_root.createEmptyMovieClip(“trail”, 1);  
trail.attachBitmap(trailbitmap, 0);  
trail\_mc.\_visible = false;  
power = 1.25;  
yspeed = 0;  
xspeed = 0;  
wind = 0;  
gravity = 0.5;  
upconstant = 0.75;  
friction = 0.99;

background.onEnterFrame = function() {  
if (Key.isDown(Key.LEFT)) {  
xspeed = xspeed+power;  
}  
if (Key.isDown(Key.RIGHT)) {  
xspeed = xspeed-power;  
}  
if (Key.isDown(Key.UP)) {  
yspeed = yspeed+power_upconstant;  
}  
if (Key.isDown(Key.DOWN)) {  
yspeed = yspeed-power_upconstant;  
}  
xspeed = xspeed\*friction;  
yspeed = yspeed-gravity;  
if (xspeed\>15) {  
xspeed = 15;  
}  
if (xspeed\<-15) {  
xspeed = -15;  
}  
if (yspeed\>15) {  
yspeed = 15;  
}  
if (yspeed\<-15) {  
yspeed = -15;  
}  
this.\_y += yspeed;  
this.\_x += xspeed;

```
starMC._rotation = starMC._rotation-xspeed;
_root.trail_mc.trail_sprite._rotation = starMC._rotation;

_root.trail_mc.trail_sprite._x = starMC._x;
_root.trail_mc.trail_sprite._y = starMC._y;

_root.trailbitmap.draw(_root.trail_mc);
trail_rectangle = new flash.geom.Rectangle(0, 0, 600, 800);
trail_blur = new flash.filters.BlurFilter(2, 3, 2);
_root.trailbitmap.applyFilter(_root.trailbitmap, trail_rectangle, new Point(0, 0), trail_blur);

```

};
