flash cs3打造跟隨鼠標的彈性球運動小遊戲

 用Flash CS3的AS製作跟隨鼠標彈性小遊戲,主要是練習AS的使用。
先看演示:
源文件下載:
[img]/Files/BeyondPic/2007-9/28/rar.gif[/img]
 
[url=http://www2.flash8.net/UploadTeach/200709/20070927115200359.rar]彈性小球運動.rar[/url]
修改文檔屬性。
[img]/Files/BeyondPic/2007-9/28/20070927115629279.gif[/img]
首先建立4個小的電影剪輯元件,分別設置如下:
[img]/Files/BeyondPic/2007-9/28/20070927115631741.gif[/img]
[img]/Files/BeyondPic/2007-9/28/20070927115632323.gif[/img]
[img]/Files/BeyondPic/2007-9/28/20070927115633347.gif[/img]
[img]/Files/BeyondPic/2007-9/28/20070927115634418.gif[/img]
回到主場景中加入如下代碼:
attachMovie("newmouse","newmouse",_root.getNextHighestDepth());
attachMovie("circle","circle",_root.getNextHighestDepth(),{_x:250, _y:200});
attachMovie("crosshair","crosshair",_root.getNextHighestDepth());
attachMovie("ball","ball",_root.getNextHighestDepth());
Mouse.hide();
friction = 0.9;
speed_scale = 0.1;
xspeed = 0;
yspeed = 0;
newmouse.onEnterFrame = function() {
    this._x = _root._xmouse;
    this._y = _root._ymouse;
};
crosshair.onEnterFrame = function() {
    this._x = _root._xmouse;
    this._y = _root._ymouse;
    dist_x = this._x-circle._x;
    dist_y = this._y-circle._y;
    distance = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
    if (distance>45) {
        angle = Math.atan2(dist_y, dist_x);
        this._x = 250+45*Math.cos(angle);
        this._y = 200+45*Math.sin(angle);
    }
 
};
ball.onEnterFrame = function() {
    dist_x = (crosshair._x-this._x)*speed_scale;
    dist_y = (crosshair._y-this._y)*speed_scale;
    xspeed += dist_x;
    yspeed += dist_y;
    xspeed *= friction;
    yspeed *= friction;
    this._x += xspeed;
    this._y += yspeed;
}; 
按Ctrl+Enter測試影片吧!
本文轉自:http://www.5uflash.com/flashjiaocheng/Flash-cs3/999.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章