[Flash Basic theory Class 15] Cool mouse [target move]

Source: Internet
Author: User

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;
 }
 //令后一个鼠标跟随前一个鼠标的位置,缓动地向前一个鼠标接近
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.