Flash AS实例教程:制作铅笔动画
- 2022-02-05
- 来源/作者: PS.ONEGREEN.ORG / 佚名
- 11 次浏览
用一段简单的AS代码就可以实现简单的铅笔动画效果。
直接复制代码,导出就可以看到效果了:_root.createEmptyMovieClip("pen", 1);
pen.lineStyle(2, 0x000000);
pen._x = 200;
pen._y = 200;
pen.beginFill(0x444444, 100);
pen.lineTo(30, -10);
pen.lineTo(200, -10);
pen.lineTo(200, 10);
pen.lineTo(30, 10);
pen.lineTo(30, -10);
pen.beginFill(0x333311, 100);
endFill(pen);
pen.beginFill(0xf9f999, 100);
pen.lineTo(0, 0);
pen.lineTo(30, 10);
pen.lineTo(30, -10);
endFill(pen);
pen._rotation = -50;
n = 0;
r = 100;
a = 1;
k = 10;
tt = 0;
lineStyle(2);
moveTo(Math.cos(0*Math.PI/180)*r+200, pen._y);
ss = setInterval(function () {
a++;
if (a>3) {
a = 1;
}
if (a == 1) {
lineStyle(2, 0xff0000);
}
if (a == 2) {
lineStyle(2, 0x00ff00);
}
if (a == 3) {
lineStyle(2, 0x0000ff);
}
n += 30
r -=0.3
if (n<20000) {
pen._x = Math.cos(n*Math.PI/180)*r+200;
pen._y = Math.sin(n*Math.PI/180)*r+200;
lineTo(pen._x, pen._y);
}
updateAfterEvent();
if (n>=20000) {
aa = setInterval(function () {
updateAfterEvent();
tt++;
if (tt>5000) {
clearInterval(aa);
clearInterval(ss);
}
pen._rotation = Math.sin(n*Math.PI/180)*5+90;
}, 5);
_root.createTextField("t", 2, 300, 350, 150, 20);
t.text = "By FLASH8菜鸟 kingofkofs";
pen._x = 400;
pen._y = 120;
}
}, 5);
sp = 0;
f = 20;
this.onEnterFrame = function() {
if (tt>5000) {
pen._y -= sp;
sp += 2;
}
if (sp>f) {
sp = -f;
if (f>=4) {
f -= 4;
}
}
};