Back to "flash Basic Theory Class-Catalog"
Before we study, let's review the previous (functional Code 07< >)
Target Move formula:
MC. Current coordinates = (MC. Target coordinates-MC. Current coordinates) * A easing constant (0 < A < 1)
For example:
There is a movie clip on the stage, with the instance named MC, which moves it to the x=400, y=300 position
mc.Tox = 400;
mc.Toy = 300;
mc.onEnterFrame = function() {
this._x += (this.Tox - this._x) * 0.3;
this._y += (this.Toy - this._y) * 0.3;
//更新每个实例的坐标了,可理解为:
//实例的 X 坐标 = 自己的X坐标 +(目标的X坐标–自己的X坐标)*0.3
//实例的 Y 坐标 = 自己的Y坐标 +(目标的Y坐标–自己的Y坐标) *0.3
};
Instance One
Ideas:
1. Copy the num mouse, the mouse's transparency diminishing (if I is incremented, n-i is diminishing);
2. Use the NUM mouse as the current mouse, others are followed;
3. Follow the principle of a previous mouse position as the target coordinates, so that the next mouse position move forward one.
Step 1:
Draw a mouse, save as a movie clip, connect-> Export-> Marker "mouse"
Step 2:
Add as code:
Mouse.hide();
//隐藏原有鼠标
var Num = 10;
//鼠标跟随的数量
for (var i = 0; i < Num; i++) {
_root.attachMovie("mouse", "m"+i, i);
//复制出Num个鼠标的影片剪辑
this["m"+i]._alpha = (Num-i) / Num * 100;
//设置出渐隐效果,每个鼠标的透明度递减
}
_root.onEnterFrame = function() {
this["m"+0]._x = _xmouse;
this["m"+0]._y = _ymouse;
//让this["m"+0]作为当前鼠标
for (var i = 1; i < Num; i++) {
this["m"+i]._x += ((this["m"+(i-1)]._x) - this["m"+i]._x) * 0.5;
this["m"+i]._y += ((this["m"+(i-1)]._y) - this["m"+i]._y) * 0.5;
}
//令后一个鼠标跟随前一个鼠标的位置,缓动地向前一个鼠标接近
};