首页  韩国资源  酷站加油  我的展厅  设计名站  古典元素  推荐下载  设计欣赏  每周专访  招募精英  人才专区  网页教程  平面设计  编程开发  设计竞赛
当前位置:首页 > 网页教程 > Flash教程 > 正文
Google
利用材质和遮照创建真实的小球动画
来源:网页教学网 作者:闪电儿 2007年06月27日 15:17 网友评论:0条 点击:
  非常不错的一个教程,在Flash中制作一个真实的小球。教程都是利用Action Script实现。在文章最后提供了所有演示效果的源文件。

  首先制作一个小球的电影元件,只要画一个圆然后转变为电影剪辑元件就可以。电影剪辑名字叫ball。

按此在新窗口浏览图片

然后在第一帧加入下面代码:

power = 0.3;
yspeed = 0;
xspeed = 0;
friction = 0.95;
_root.attachMovie("ball", "ball", 1, {_x:250, _y:175});
ball.onEnterFrame = function() {
    if (Key.isDown(Key.LEFT)) {
        xspeed -= power;
    }
    if (Key.isDown(Key.RIGHT)) {
        xspeed += power;
    }
    if (Key.isDown(Key.UP)) {
        yspeed -= power
    }
    if (Key.isDown(Key.DOWN)) {
        yspeed += power
    }
    
    xspeed *= friction;
    
    this._y += yspeed;
    this._x += xspeed;
}; 

效果如下:(按键盘方向键可以看到效果)

/UploadTeach/200706/2007062522129246.swf

给小球来个渐变填充,象一个球了!呵呵...

/UploadTeach/200706/2007062522150833.swf

再来个阴影:

/UploadTeach/200706/2007062522211645.swf

下面我们再引入一幅材质图案,库面板如下:

按此在新窗口浏览图片

效果如下:

/UploadTeach/200706/2007062522322219.swf

然后利用ActionScript加上遮照。主要是利用mc.setMask()函数设置遮照了!

power = 0.3;
yspeed = 0;
xspeed = 0;
friction = 0.95;
_root.attachMovie("ball", "ball", 1, {_x:250, _y:175});
ball.texture.setMask(ball.ball_itself);
ball.onEnterFrame = function() {
    if (Key.isDown(Key.LEFT)) {
        xspeed -= power;
    }
    if (Key.isDown(Key.RIGHT)) {
        xspeed += power;
    }
    if (Key.isDown(Key.UP)) {
        yspeed -= power
    }
    if (Key.isDown(Key.DOWN)) {
        yspeed += power
    }
    xspeed *= friction;
    this._y += yspeed;
    this._x += xspeed;
}; 

效果如下:

/UploadTeach/200706/2007062522401918.swf

然后我们让该球真的滚动起来,滚动的更加真实:

power = 0.3;
yspeed = 0;
xspeed = 0;
friction = 0.95;
_root.attachMovie("ball", "ball", 1, {_x:250, _y:175});
ball.texture.setMask(ball.ball_itself);
ball.onEnterFrame = function() {
    if (Key.isDown(Key.LEFT)) {
        xspeed -= power;
    }
    if (Key.isDown(Key.RIGHT)) {
        xspeed += power;
    }
    if (Key.isDown(Key.UP)) {
        yspeed -= power;
    }
    if (Key.isDown(Key.DOWN)) {
        yspeed += power;
    }
    xspeed *= friction;
    yspeed *= friction;
    this._y += yspeed;
    this._x += xspeed;
    this.texture._y += yspeed;
    this.texture._x += xspeed;
    if (this.texture._x>158) {
        this.texture._x -= 188;
    }
    if (this.texture._x<-158) {
        this.texture._x += 188;
    }
    if (this.texture._y>158) {
        this.texture._y -= 188;
    }
    if (this.texture._y<-158) {
        this.texture._y += 188;
    }
}; 

效果如下:

/UploadTeach/200706/2007062522440555.swf

下面是另外一种材质制作的动画:

/UploadTeach/200706/2007062522501459.swf

最后把上面的7个演示动画的源文件提供给大家:小球动画.rar

上一篇:Flex 2.0实现SWF全屏   下一篇:Flash制作红外线引导导弹爆炸视觉效果
收藏此页】【打印】【关闭
 相关文章  我要点评
·PS制作材质压花效果
·一个用遮照做的FLASH效果

免责声明:本站刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。对本文有任何异议,请联络:68design#163.com
转载要求:作者及来源信息必需保留。转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印。



关于我们 | 在线反馈 | 广告报价 | 友情链接 | 联系我们 | 免责声明 | 在线投稿 | 网站地图
Copyright © 2003-2007 68design.net, All Rights Reserve 【找网页设计师,当然上网页设计师联盟】