CGArt-中国CGer中的绿色家园
首页 信息动态 原创排行 互动教程 资源千寻 CG人才 CGArt杂志 艺术设计 CG画廊 CG论坛 酷站欣赏 CG搜索 会员中心
Flash利用材质和遮照创建真实的小球动画
来源:网页教学网 作者:闪电儿 编辑:浪漫的季节 发布时间:2007年06月25日 11:49:05

非常不错的一个教程,在Flash中制作一个真实的小球。教程都是利用Action Script实现。在文章最后提供了所有演示效果的源文件。

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

Flash利用材质和遮照创建真实的小球动画

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

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;
};

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



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



再来个阴影。



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

Flash利用材质和遮照创建真实的小球动画

效果如下:

然后利用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;
};

效果如下:



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

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;
    }
};

效果如下:



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



最后把上面的7个演示动画的源文件提供给大家:点击这里下载源文件

共有评论0条
更多评论..
作者信息 详细信息
评论人:
验证码:
内容:
 
about us advertisement publish conformity service cooperate associate link site map contact us help jump to the top of page