注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

清风的博客

我为人人,人人为我。

 
 
 

日志

 
 

两点间画线  

2014-01-05 15:13:54|  分类: 【flash教程】 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

1、画直线:过程只有简单的一步搞定,在主场景时间轴第一帧输入代码如下

onMouseDown = function () {
depth = getNextHighestDepth(); //取得下一个可用的最大深度
drawing = true; //当鼠标按下绘画开始
x0 = _root._xmouse; //取得绘画位置
y0 = _root._ymouse;
};
onMouseMove = function () {
if (drawing) {
_root.createEmptyMovieClip("line"+depth, depth); // 创建一个空影片剪辑在主场景中
with (_root["line"+depth]) { //更改线条属性
moveTo(x0, y0); //移动绘画位置到鼠标按下的地方
lineStyle(0, 0x73179B, 100); //0表线条粗细为极细,中间的表颜色,100表示透明度为100
lineTo(_root._xmouse, _root._ymouse); //画直线到鼠标位置
}
}
};
onMouseUp = function () { // 鼠标放开时
drawing = false; //绘画结束
};

2、任意画线:

     给大家简单介绍一下Flash中使用AS来画线,从下面这个函数开始吧! _root.createEmptyMovieClip("terrain", 1);  
这个函数的功能是创建一个空的MC,名字为terrain。然后开始画线

:_root.terrain.lineStyle(10, 0xff0000, 100); 
10代表线的粗细;0xff0000代表线颜色;100代表线的alpha为100。你可以查看一下手册lineStyle函数的使用。下面开始具体给出画线的代码:

画红色矩形:

createEmptyMovieClip("terrain", 1);
terrain.lineStyle(10, 0xff00ff, 100);
terrain.moveTo(100, 100);
terrain.lineTo(300, 100);
terrain.lineTo(300, 300);
terrain.lineTo(100, 300);
terrain.lineTo(100, 100);
鼠标画线:

createEmptyMovieClip("terrain", 1);
terrain.lineStyle(10, 0xff00ff, 100);
onEnterFrame = function () {
    terrain.lineTo(_xmouse, _ymouse);
}; 
改变帧频为50fps。

 只有按一下鼠标才能画:

createEmptyMovieClip("terrain", 1);
terrain.lineStyle(10, 0xff00ff, 100);
imdrawing = false;
onMouseDown = function () {
    if (imdrawing == false) {
        terrain.moveTo(_xmouse, _ymouse);
        imdrawing = true;
    }
    if (imdrawing == true) {
        onEnterFrame = function () {
            terrain.lineTo(_xmouse, _ymouse);
        };
    }
};
onMouseUp = function () {
    onEnterFrame = function () {
        imdrawing = false;
    };
}; 
添加一些其它的画线效果:

import flash.filters.BevelFilter;
var distance:Number = 2;
var angleInDegrees:Number = 45;
var highlightColor:Number = 0xff00ff;
var highlightAlpha:Number = 1;
var shadowColor:Number = 0xbb00bb;
var shadowAlpha:Number = 1;
var blurX:Number = 8;
var blurY:Number = 8;
var strength:Number = 10;
var quality:Number = 3;
var type:String = "inner";
var knockout:Boolean = false;
var my_bevel_filter:BevelFilter = new BevelFilter(distance, angleInDegrees, highlightColor, highlightAlpha, shadowColor,
shadowAlpha, blurX, blurY, strength, quality, type, knockout);
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(20, 0xdd00dd, 100);
terrain.filters = new Array(my_bevel_filter);
imdrawing = false;
onMouseDown = function () {
    if (imdrawing == false) {
        terrain.moveTo(_xmouse, _ymouse);
        imdrawing = true;
    }
    if (imdrawing == true) {
        onEnterFrame = function () {
            terrain.lineTo(_xmouse, _ymouse);
        };
    }
};
onMouseUp = function () {
    onEnterFrame = function () {
        imdrawing = false;
    };
}; 
模糊效果画线:

import flash.filters.BlurFilter;
var blurX:Number = 30;
var blurY:Number = 30;
var quality:Number = 3;
var my_blur_filter:BlurFilter = new BlurFilter(blurX, blurY, quality);
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(20, 0xdd00dd, 100);
terrain.filters = new Array(my_blur_filter);
imdrawing = false;
onMouseDown = function () {
    if (imdrawing == false) {
        terrain.moveTo(_xmouse, _ymouse);
        imdrawing = true;
    }
    if (imdrawing == true) {
        onEnterFrame = function () {
            terrain.lineTo(_xmouse, _ymouse);
        };
    }
};
onMouseUp = function () {
    onEnterFrame = function () {
        imdrawing = false;
    };
}; 
发光效果画线代码:

import flash.filters.GlowFilter;
var color:Number = 0x33CCFF;
var alpha:Number = .8;
var blurX:Number = 35;
var blurY:Number = 35;
var strength:Number = 2;
var quality:Number = 3;
var inner:Boolean = false;
var knockout:Boolean = false;
var my_glow_filter:GlowFilter = new GlowFilter(color, alpha, blurX, blurY, strength, quality, inner, knockout);
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(20, 0xdd00dd, 100);
terrain.filters = new Array(my_glow_filter);
imdrawing = false;
onMouseDown = function () {
    if (imdrawing == false) {
        terrain.moveTo(_xmouse, _ymouse);
        imdrawing = true;
    }
    if (imdrawing == true) {
        onEnterFrame = function () {
            terrain.lineTo(_xmouse, _ymouse);
        };
    }
};
onMouseUp = function () {
    onEnterFrame = function () {
        imdrawing = false;
    };
};  
画阴影线的代码:

import flash.filters.DropShadowFilter;
var distance:Number = 20;
var angleInDegrees:Number = 45;
var color:Number = 0x000000;
var alpha:Number = .8;
var blurX:Number = 16;
var blurY:Number = 16;
var strength:Number = 1;
var quality:Number = 3;
var inner:Boolean = false;
var knockout:Boolean = false;
var hideObject:Boolean = false;
var my_shadow_filter:DropShadowFilter = new DropShadowFilter(distance, angleInDegrees, color, alpha, blurX, blurY, strength, quality, inner, knockout, hideObject);
createEmptyMovieClip("terrain", 1);
terrain.lineStyle(20, 0xdd00dd, 100);
terrain.filters = new Array(my_shadow_filter);
imdrawing = false;
onMouseDown = function () {
    if (imdrawing == false) {
        terrain.moveTo(_xmouse, _ymouse);
        imdrawing = true;
    }
    if (imdrawing == true) {
        onEnterFrame = function () {
            terrain.lineTo(_xmouse, _ymouse);
        };
    }
};
onMouseUp = function () {
    onEnterFrame = function () {
        imdrawing = false;
    };
}; 
上面所有效果都混合在一起:

// bevel filter
import flash.filters.BevelFilter;
var distance:Number = 5;
var angleInDegrees:Number = 45;
var highlightColor:Number = 0xFFFF00;
var highlightAlpha:Number = .8;
var shadowColor:Number = 0x0000FF;
var shadowAlpha:Number = .8;
var blurX:Number = 5;
var blurY:Number = 5;
var strength:Number = 5;
var quality:Number = 3;
var type:String = "inner";
var knockout:Boolean = false;
var my_bevel_filter:BevelFilter = new BevelFilter(distance, angleInDegrees, highlightColor, highlightAlpha, shadowColor,
shadowAlpha, blurX, blurY, strength, quality, type, knockout);
// blur filter
import flash.filters.BlurFilter;
var blurX:Number = 30;
var blurY:Number = 30;
var quality:Number = 3;
var my_blur_filter:BlurFilter = new BlurFilter(blurX, blurY, quality);
// shadow
import flash.filters.DropShadowFilter;
var distance:Number = 20;
var angleInDegrees:Number = 45;
var color:Number = 0x000000;
var alpha:Number = .8;
var blurX:Number = 16;
var blurY:Number = 16;
var strength:Number = 1;
var quality:Number = 3;
var inner:Boolean = false;
var knockout:Boolean = false;
var hideObject:Boolean = false;
var my_shadow_filter:DropShadowFilter = new DropShadowFilter(distance, angleInDegrees, color, alpha, blurX, blurY, strength, quality, inner, knockout, hideObject);
// glow
import flash.filters.GlowFilter;
var color:Number = 0x33CCFF;
var alpha:Number = .8;
var blurX:Number = 35;
var blurY:Number = 35;
var strength:Number = 2;
var quality:Number = 3;
var inner:Boolean = false;
var knockout:Boolean = false;
var my_glow_filter:GlowFilter = new GlowFilter(color, alpha, blurX, blurY, strength, quality, inner, knockout);
_root.createEmptyMovieClip("terrain", 1);
_root.terrain.lineStyle(10, 0xff00ff, 100);createEmptyMovieClip("terrain", 1);
terrain.lineStyle(20, 0xdd00dd, 100);
terrain.filters = new Array(my_shadow_filter,my_glow_filter,my_blur_filter,my_bevel_filter);
imdrawing = false;
onMouseDown = function () {
    if (imdrawing == false) {
        terrain.moveTo(_xmouse, _ymouse);
        imdrawing = true;
    }
    if (imdrawing == true) {
        onEnterFrame = function () {
            terrain.lineTo(_xmouse, _ymouse);
        };
    }
};
onMouseUp = function () {
    onEnterFrame = function () {
        imdrawing = false;
    };
}; 
 

  评论这张
 
阅读(11)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017