分类

安卓应用安卓游戏攻略资讯

Flash

Flash 3d效果精彩实例--鼠标3D感应

作者:佚名 来源: JZ5U整理 日期:2005-8-20 22:35:02
Flash在3D应用领域非常广阔,使用Flash可以很轻松的做出一些精彩奇妙的3D特效,而且许多效果可以响应鼠标的动作,此实例就是一个鼠标3D感应的效果,通过移动鼠标,可以影响影片中的3D小球,最终效果如图1所示:


图1 最终效果

1.启动Flash,新建一个影片,设置影片的舞台大小为250px*250px(单位为象素),设置影片的背景颜色为黑色.

2.新建一个影片剪辑元件,命名为Ball,进入元件的编辑区后,使用椭圆工具绘制一个正圆,然后打开混色器面板,在面板中设置填充类型为放射渐变,分别设置色带下左右两个色块的颜色,如图2所示:


图2 设置填充色

其中左边色块的RGB颜色代码为(103,152,116),右边色块的RGB颜色代码为(0,0,0),小球填充后的效果如图3所示:


图3 填充颜色后的小球

3.新建一个影片剪辑元件,命名为Point,进入元件的编辑区后,从库中将元件Ball拖到编辑区中,然后在属性面板中给其设置实例名为bLur,如图4所示;


图4 给小球设置实例名

4.还是新建一个影片剪辑元件,命名为Balls,进入元件的编辑区后,将影片默认的图层重命名为Point,然后将元件Point拖到编辑区中,同时在属性面板中设置其实例名为Point,如图5所示;


图5 设置实例名Point

在上面新建一个图层Actions,用来设置控制影片的Action动作脚本.

给第1帧添加如下Action:

x1 = "0"
  y1 = "0";
  z1 = "50";
  x2 = "0";
  y2 = "0";
  z2 = "-50";
  x3 = ".1";
  y3 = ".1";
  z3 = ".1";
  x4 = "0";
  y4 = "0";
  z4 = "-100";
  x5 = "-50";
  y5 = "-50";
  z5 = "50";
  x6 = "50";
  y6 = "-50";
  z6 = "50";
  x7 = "50";
  y7 = "50";
  z7 = "50";
  x8 = "-50";
  y8 = "50";
  z8 = "50";
  d = "900";
  z0 = "1000";
  i = "1";
  while (Number(i)<9) {
  duplicateMovieClip("point", "point" add i, 20-(i*2));
  set("zsort" add i, i);
  i = Number(i)+1;
  }

给第2帧添加如下Action:

yangle = int(/:yangle);
  xangle = int(/:xangle);
  i = "1";
  while (Number(i)<9) {
  cosYangle = eval ( "/:cos" add yangle );
  sinYangle = eval ( "/:sin" add yangle );
  cosXangle = eval ( "/:cos" add xangle );
  sinXangle = eval ( "/:sin" add xangle );
  zpos = eval("z" add i);
  xpos = eval("x" add i);
  ypos = eval("y" add i);
  tempz = ((eval("z" add i) ) * cosYangle ) - ( eval ("x" add i) * sinYangle );
  set("x" add i, Number((zpos*sinYangle))+Number((xpos*cosYangle)));
  set("z" add i, Number(((ypos)*sinXangle))+Number((tempz*cosXangle)));
  set("y" add i, ((ypos)*cosXangle)-(tempz*sinXangle));
  scalar = 1/ ( ((eval ("z" add i))/d)+1 );
  set("xp" add i, ((eval("x" add i) * scalar) + 00));
  set("yp" add i, ((eval("y" add i) * scalar) + 00));
  set("unseen" add i, true);
  i = Number(i)+1;
  }
  n = "2";
  while ((Number(n)<9)) {
  i = 8;
  dummy = "nada";
  while (Number(i)>=Number(n)) {
  if (eval ("z" add eval("zsort" add (i-1))) > eval ("z" add eval("zsort" add i))) {
  dummy = eval("zsort" add (i-1));
  set("zsort" add (i-1), eval("zsort" add i));
  set("zsort" add i, dummy);
  }
  i = i-1;
  }
  if (dummy eq "nada") {
  n = 9;
  }
  n = Number(n)+1;
  }
  i = "1";
  while (Number(i)<9) {
  /:blur = int (15 - (eval( "z" add eval ("zsort" add i) )/5));
  tellTarget ("point" add i add "/blur") {
  gotoAndStop(/:blur);
  }
  setProperty("point" add i, _xscale, 100 - ((eval( "z" add eval ("zsort" add i))) /5));
  setProperty("point" add i, _yscale, 100 - ((eval( "z" add eval ("zsort" add i))) /5));
  setProperty("point" add i, _x, eval( "xp" add eval ("zsort" add i) ));
  setProperty("point" add i, _y, eval( "yp" add eval ("zsort" add i) ));
  i = Number(i)+1;
  }

给第3帧添加如下Action:

gotoAndPlay(2);

最后时间轴如图6所示:


图6 元件Balls的时间轴窗口

5.因为影片中还需要使用鼠标来对小球进行控制,我们可以利用隐形按钮来实现这一功能.新建一个按钮元件命名为yxbtn,进入元件的编辑区后,只在Hit帧绘制一个图形即可,形状可以随意.然后再新建一个影片剪辑元件,命名为inv,进入元件的编辑区后,将元件yxbtn拖到编辑区中,然后将图层Layer1延伸到第2帧,然后在上面新建一个图层,在第1帧添加如下Action:

xoffset = int(xoldpos-getProperty("/inv", _x))
  yoffset = int(getProperty("/inv", _y)-yoldpos);
  if (((Number(xoffset) == 0) and (Number(yoffset) == 0)) or (not over)) {
  /:xangle = (/:xangle-(/:xangle/20));
  /:yangle = (/:yangle-(/:yangle/20));
  } else {
  /:xangle = yoffset;
  /:yangle = xoffset;
  }
  if ((Number(/:xangle)>40)) {
  /:xangle = "40";
  } else if ((Number(/:xangle)  /:xangle = "-40";
  }
  if ((Number(/:yangle)>40)) {
  /:yangle = "40";
  } else if ((Number(/:yangle)  /:yangle = "-40";
  }
  xoldpos = getProperty("/inv", _x);
  yoldpos = getProperty("/inv", _y);

在第2帧添加如下Action:

gotoAndPlay(1);

最后工作区如图7所示;


图7 工作区状态

6.最后回到主场景中,添加三个图层,从上到下分别命名为initialize, inv和Balls,在图层Inv和Balls的第4帧分别插入一个关键帧,然后从图库中将元件Inv和Balls分别拖到图层Inv和图层Balls中,同时在属性面板中分别设置其实例名为Inv和Balls,如图8所示;


图8 布置主场景

7.回到图层initialize,给第1帧添加如下Action:

xangle = "5";
yangle = "5";

在第2帧添加如下Action:

set("cos-42", 0.743144825451055);
  set("cos-41", 0.754709580197564);
  set("cos-40", 0.766044443094884);
  set("cos-39", 0.777145961433975);
  set("cos-38", 0.788010753584805);
  set("cos-37", 0.798635510026434);
  set("cos-36", 0.809016994355128);
  set("cos-35", 0.819152044270192);
  set("cos-34", 0.829037572537239);
  set("cos-33", 0.838670567928596);
  set("cos-32", 0.848048096140553);
  set("cos-31", 0.857167300687171);
  set("cos-30", 0.866025403770406);
  set("cos-29", 0.874619707126247);
  set("cos-28", 0.882947592846643);
  set("cos-27", 0.891006524176917);
  set("cos-26", 0.898794046288515);
  set("cos-25", 0.906307787026791);
  set("cos-24", 0.913545457633494);
  set("cos-23", 0.920504853444072);
  set("cos-22", 0.927183854559112);
  set("cos-21", 0.933580426490206);
  set("cos-20", 0.939692620779555);
  set("cos-19", 0.945518575593583);
  set("cos-18", 0.951056516290005);
  set("cos-17", 0.956304755958442);
  set("cos-16", 0.961261695934258);
  set("cos-15", 0.965925826285507);
  set("cos-14", 0.970295726272901);
  set("cos-13", 0.974370064782571);
  set("cos-12", 0.97814760073155);
  set("cos-11", 0.981627183445777);
  set("cos-10", 0.984807753010664);
  set("cos-9", 0.987688340593903);
  set("cos-8", 0.990268068740611);
  set("cos-7", 0.992546151640607);
  set("cos-6", 0.994521895367765);
  set("cos-5", 0.996194698091423);
  set("cos-4", 0.997564050259649);
  set("cos-3", 0.998629534754517);
  set("cos-2", 0.999390827019125);
  set("cos-1", 0.999847695156465);
  set("cos0", 1);
  set("cos1", 0.999847695156465);
  set("cos2", 0.999390827019125);
  set("cos3", 0.998629534754517);
  set("cos4", 0.997564050259649);
  set("cos5", 0.996194698091423);
  set("cos6", 0.994521895367765);
  set("cos7", 0.992546151640607);
  set("cos8", 0.990268068740611);
  set("cos9", 0.987688340593903);
  set("cos10", 0.984807753010664);
  set("cos11", 0.981627183445777);
  set("cos12", 0.97814760073155);
  set("cos13", 0.974370064782571);
  set("cos14", 0.970295726272901);
  set("cos15", 0.965925826285507);
  set("cos16", 0.961261695934258);
  set("cos17", 0.956304755958442);
  set("cos18", 0.951056516290005);
  set("cos19", 0.945518575593583);
  set("cos20", 0.939692620779555);
  set("cos21", 0.933580426490206);
  set("cos22", 0.927183854559112);
  set("cos23", 0.920504853444072);
  set("cos24", 0.913545457633494);
  set("cos25", 0.906307787026791);
  set("cos26", 0.898794046288515);
  set("cos27", 0.891006524176917);
  set("cos28", 0.882947592846643);
  set("cos29", 0.874619707126247);
  set("cos30", 0.866025403770406);
  set("cos31", 0.857167300687171);
  set("cos32", 0.848048096140553);
  set("cos33", 0.838670567928596);
  set("cos34", 0.829037572537239);
  set("cos35", 0.819152044270192);
  set("cos36", 0.809016994355128);
  set("cos37", 0.798635510026434);
  set("cos38", 0.788010753584805);
  set("cos39", 0.777145961433975);
  set("cos40", 0.766044443094884);
  set("cos41", 0.754709580197564);

在第3帧添加如下Action:

set("sin-42", -0.669130606388214);
  set("sin-41", -0.65605902901961);
  set("sin-40", -0.642787609715359);
  set("sin-39", -0.629320391078343);
  set("sin-38", -0.615661475353822);
  set("sin-37", -0.60181502317984);
  set("sin-36", -0.587785252319867);
  set("sin-35", -0.573576436378012);
  set("sin-34", -0.559192903497261);
  set("sin-33", -0.544639035041061);
  set("sin-32", -0.529919264258734);
  set("sin-31", -0.515038074935051);
  set("sin-30", -0.500000000024441);
  set("sin-29", -0.4848096202702);
  set("sin-28", -0.469471562809151);
  set("sin-27", -0.453990499762182);
  set("sin-26", -0.438371146811064);
  set("sin-25", -0.422618261762019);
  set("sin-24", -0.406736643096434);
  set("sin-23", -0.390731128509199);
  set("sin-22", -0.37460659343508);
  set("sin-21", -0.35836794956371);
  set("sin-20", -0.34202014334332);
  set("sin-19", -0.32556815447403);
  set("sin-18", -0.309016994391028);
  set("sin-17", -0.292371704738003);
  set("sin-16", -0.275637355831441);
  set("sin-15", -0.258819045116126);
  set("sin-14", -0.241921895612425);
  set("sin-13", -0.224951054355759);
  set("sin-12", -0.207911690828781);
  set("sin-11", -0.190808995386685);
  set("sin-10", -0.173648177676178);
  set("sin-9", -0.156434465048579);
  set("sin-8", -0.139173100967505);
  set("sin-7", -0.121869343411672);
  set("sin-6", -0.104528463273256);
  set("sin-5", -0.0871557427523399);
  set("sin-4", -0.0697564737478767);
  set("sin-3", -0.0523359562457615);
  set("sin-2", -0.0348994967043783);
  set("sin-1", -0.0174524064382223);
  set("sin0", 0);
  set("sin1", 0.0174524064382223);
  set("sin2", 0.0348994967043783);
  set("sin3", 0.0523359562457615);
  set("sin4", 0.0697564737478767);
  set("sin5", 0.0871557427523399);
  set("sin6", 0.104528463273256);
  set("sin7", 0.121869343411672);
  set("sin8", 0.139173100967505);
  set("sin9", 0.156434465048579);
  set("sin10", 0.173648177676178);
  set("sin11", 0.190808995386685);
  set("sin12", 0.207911690828781);
  set("sin13", 0.224951054355759);
  set("sin14", 0.241921895612425);
  set("sin15", 0.258819045116126);
  set("sin16", 0.275637355831441);
  set("sin17", 0.292371704738003);
  set("sin18", 0.309016994391028);
  set("sin19", 0.32556815447403);
  set("sin20", 0.34202014334332);
  set("sin21", 0.35836794956371);
  set("sin22", 0.37460659343508);
  set("sin23", 0.390731128509199);
  set("sin24", 0.406736643096434);
  set("sin25", 0.422618261762019);
  set("sin26", 0.438371146811064);
  set("sin27", 0.453990499762182);
  set("sin28", 0.469471562809151);
  set("sin29", 0.4848096202702);
  set("sin30", 0.500000000024441);
  set("sin31", 0.515038074935051);
  set("sin32", 0.529919264258734);
  set("sin33", 0.544639035041061);
  set("sin34", 0.559192903497261);
  set("sin35", 0.573576436378012);
  set("sin36", 0.587785252319867);
  set("sin37", 0.60181502317984);
  set("sin38", 0.615661475353822);
  set("sin39", 0.629320391078343);
  set("sin40", 0.642787609715359);
  set("sin41", 0.65605902901961);

最后时间轴窗口如图9所示:


图9 主场景时间轴窗口


展开

文章推荐

应用推荐

网友评论