文章搜索:
打开支付宝首页搜索“510617664”,即可领红包
  首页--> 计算机--> FLASH教程
 
用Flash制作一个类似弹弓的小游戏教程
http://www.xxqqss.com 学习轻松网 点击量:6066
 
attachMovie("sling", "sling_1", _root.getNextHighestDepth(), {_x:20, _y:200});
attachMovie("sling", "sling_2", _root.getNextHighestDepth(), {_x:480, _y:200});
attachMovie("ball", "ball", _root.getNextHighestDepth(), {_x:250, _y:100});
_root.createEmptyMovieClip("elastic", _root.getNextHighestDepth());
ball.onPress = function() {
    startDrag(this);
};
ball.onRelease = function() {
    stopDrag();
};
elastic.onEnterFrame = function() {
    this.clear();
    this.lineStyle(2, 0x009900);
    this.moveTo(sling_1._x, sling_1._y);
    if (ball._y>182) {
        dist_x = ball._x-sling_1._x;
        dist_y = ball._y-sling_1._y;
        distance_from_sling = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
        elastic_length = Math.sqrt(distance_from_sling*distance_from_sling-18*18);
        angle = Math.atan2(dist_y, dist_x)+Math.asin(18/distance_from_sling);
        this.lineTo(sling_1._x+elastic_length*Math.cos(angle), sling_1._y+elastic_length*Math.sin(angle));
    } else {
        this.lineTo(sling_2._x, sling_2._y);
    }
    this.moveTo(sling_2._x, sling_2._y);
    if (ball._y>182) {
        dist_x = ball._x-sling_2._x;
        dist_y = ball._y-sling_2._y;
        distance_from_sling = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
        elastic_length = Math.sqrt(distance_from_sling*distance_from_sling-18*18);
        angle = Math.atan2(dist_y, dist_x)+Math.asin(18/distance_from_sling)*-1;
        this.lineTo(sling_2._x+elastic_length*Math.cos(angle), sling_2._y+elastic_length*Math.sin(angle));
    } else {
        this.lineTo(sling_2._x, sling_2._y);
    }
}; 

测试效果:

/UploadTeach/200709/20070919135425883.swf

在这里我们可以很轻松的计算出小球在线上的角度来。

按此在新窗口浏览图片

稍微做一下改动。

来源:网页教学网  作者:闪电儿


打印】 【关闭
免责声明 :本站刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。对本文有任何异议,请发送fiyeadwyv@163.com
最热门点击排行
 
版权所有 2006-2021:学习轻松网 Copyright http://www.xxqqss.com All rights reserved 浙ICP备14013707号-1
广告联系电话: 13958357030 联系QQ:9792414 工具条下载