首页--> 计算机--> FLASH教程
 
用Flash制作一个类似弹弓的小游戏教程
http://www.xxqqss.com 学习轻松网 发布日期:2007/9/20 点击量:6372
 
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
【免费游戏赚钱网址导航】(站长QQ:9792414)多站号请误用相同密码 【站长信箱】幸运28交流群号:122287647
游戏赚钱平台
注册地址
企业/个人
企业
 有赚网与蹦蹦网是深度合作关系
企业
手机app端赚钱名称
下载安装后输入邀请码领额外红包
估计日赚收入(亲体验)
下载方式
闪电盒子
邀请码:413270540831
3元
 安卓手机各应用市场(推荐应用宝),苹果手机输入名称查找。
中青看点
邀请码:25741975
2元
趣头条
邀请码:A443657406
1元
 
健康游戏忠告:抵制不良游戏,拒绝盗版游戏;注意自我保护,谨防受骗上当;适度游戏益脑,沉迷游戏伤身;合理安排时间,享受健康生活。
本站声明不参与任何游戏网站经营事宜,如果你和第三方游戏网站产生纠纷事宜请自行协商解决,本站感谢你的支持和理解。
站长QQ:9792414