第一節(jié):3D鼠標(biāo)跟隨
該實例實現(xiàn)的是一3D小球隨“鼠標(biāo)”跟隨效果,在制作過程中主要使用了自定義函數(shù)進行影片控制,大量使用了循環(huán)語句和賦值語句。影片最終播放效果如圖1.1所示:
圖1.1 影片最終效果
1.新建一影片,通過屬性面板設(shè)置其大小為600pxX450px(單位為象素)背景色為#000000。
2.新建一影片剪輯“Sphere”,選取“橢圓工具”,在工作區(qū)中繪制一橢圓,并去掉其輪廓。打開“混色器”面板進行如圖1.2所示的設(shè)置:
圖1.2 設(shè)置“混色器”面板
3.應(yīng)用上面設(shè)置的填充色填充繪制的圓,并通過“填充漸變”工具設(shè)置其光線注入點效果使之給人一種很強的立體感,效果如圖1.3所示:
圖1.3 制作“sphere”
4.新建一影片剪輯“coursor”用線條工具在工作區(qū)中繪制如圖1.4所示的鼠標(biāo)圖案,并設(shè)置其填充色為白色,并去除其輪廓線:
圖1.4 鼠標(biāo)制作
5.新建一影片剪輯“animation”,將默認圖層命名為“animation”,“ animation”只有一個圖層,同時只有四幀。下面將分別為這四個關(guān)鍵幀進行相應(yīng)設(shè)置
選中第1關(guān)鍵幀,添加如下ActionScript腳本代碼:
// creazione della classe PuntoSpaziale
function PuntoSpaziale (x, y, z, target) {
// propriet?
this.target = target;
this.x = x;
this.y = y;
this.z = z;
this.firstx = x;
this.firsty = y;
this.firstz = z;
this.DFOWA = 100;
// Distance From Object World Axes
this.DFPP = 200;
// Distance From Proiection Plain
this.ScreenCenter_x = 300;
this.ScreenCenter_y = 200;
this.speed2dx = 0;
this.speed2dy = 0;
// metodi
this.Coord2DRelativeTo = Coord2DRelativeTo;
this.Coord3DRelativeTo = Coord3DRelativeTo;
this.Rotate = Rotate;
this.Scale = Scale;
this.UScale = UScale;
this.Traslate = Traslate;
this.Proiection_y = Proiection_y;
this.Proiection_x = Proiection_x;
this.DrawPoint = DrawPoint;
// funzioni che definiscono i metodi
function Coord3DRelativeTo (x1, y1, z1) {
// cambio di coordinate 3D in riferimento ad un'altro punto
this.x -= x1;
this.y -= y2;
this.z -= z3;
}
function Coord2DRelativeTo (x, y) {
// cambio di coordinate "D di proiezione in riferimento ad un'altro punto
// per esempio si pu?usare per centrare il punto (0,0) al centro dello schermo
// ( in tal caso passare come parametri le coordinate di tale centro )
this.ScreenCenter_x = x;
this.ScreenCenter_y = y;
}
function Rotate (teta_x, teta_y, teta_z) {
// rotazione intorno agli assi x, y e z espressa in radianti
if (teta_x != 0) {
ytemp = this.y;
this.y = this.y*Math.cos(teta_x)-this.z*Math.sin(teta_x);
this.z = ytemp*Math.sin(teta_x)+this.z*Math.cos(teta_x);
}
if (teta_y != 0) {
xtemp = this.x;
this.x = this.x*Math.cos(teta_y)+this.z*Math.sin(teta_y);
this.z = this.z*Math.cos(teta_y)-xtemp*Math.sin(teta_y);
}
if (teta_z != 0) {
xtemp = this.x;
this.x = this.x*Math.cos(teta_z)-this.y*Math.sin(teta_z);
this.y = this.y*Math.cos(teta_z)+xtemp*Math.sin(teta_z);
}
}
function Scale (sx, sy, sz) {
// scalamento non uniforme
this.x *= sx;
this.y *= sy;
this.z *= sx;
}
function UScale (s) {
// scalamento uniforme
this.x *= s;
this.y *= s;
this.z *= s;
}
function Traslate (a, b, c) {
// traslazione
this.x += a;
this.y += b;
this.z += c;
}
function DrawPoint (i) {
// caratterrizza il nome e la profondit?dell'istanza duplicata
duplicateMovieClip (this.target, "punto"+i, i);
mymovieclip = eval("punto"+i);
setProperty ("punto"+i, _x, this.Proiection_x());
setProperty ("punto"+i, _y, this.Proiection_y());
setProperty ("punto"+i, _xscale, (100/(((this.z+this.DFOWA)/this.DFPP)+1)));
setProperty ("punto"+i, _yscale, (100/(((this.z+this.DFOWA)/this.DFPP)+1)));
myColor = new Color(eval("punto"+i));
myColorTransform = new Object();
s = (this.z+50)/1;
myColorTransform = {ra:'100', rb:-s, ga:'100', gb:-s, ba:'100', bb:-s, aa:'100', ab:'0'};
myColor.setTransform(myColorTransform);
}
function Proiection_x () {
// coordinata x della proiezione
this.proiectionx = (this.x/(((this.z+this.DFOWA)/this.DFPP)+1)+this.ScreenCenter_x);
return (this.x/(((this.z+this.DFOWA)/this.DFPP)+1)+this.ScreenCenter_x);
}
function Proiection_y () {
// coordinata y della proiezione
this.proiectiony = (this.y/(((this.z+this.DFOWA)/this.DFPP)+1)+this.ScreenCenter_y);
return (this.y/(((this.z+this.DFOWA)/this.DFPP)+1)+this.ScreenCenter_y);
}
}
// Funzione che prende un array di valori numerici e restituisce un
// array delle stesse dimensioni contenente nella prima posizione
// il numero ordinele che indica a che posto ?il primo elemento
// dell'array input quanto a grandezza
// per esempio se il primo elemento ?il pi?grande allora nell'array
// restituito avr?1 nella prima pos. Se ?il quarto pi?grande avr?
// 4 etc.....
// nel caso di due elementi coincidenti l'indice relativo sar?comunque diverso secondo un criterio casuale
function OrdIndex (InputArray) {
len = InputArray.length;
for (var e = 0; e
InputArray[e] = InputArray[e]+Math.random()/100000000;
}
Index = new Array(len);
for (var i = 0; i
var count = 0;
for (var j = 0; j
if (InputArray[i]<=InputArray[j]) {
count++;
}
}
Index[i] = count;
}
return Index;
}
選中第2關(guān)鍵幀,添加如下ActionScript腳本代碼:
xrotation = 0;
yrotation = 0;
xposition = 0;
yposition = 0;
depth = 0;
var miopunto1 = new Puntospaziale(0, -25, 50, "point");
var miopunto2 = new Puntospaziale(-43.3, -25, -25, "point");
var miopunto3 = new Puntospaziale(43.3, -25, -25, "point");
var miopunto4 = new Puntospaziale(0, 43.3, 0, "point");
var miopunto5 = new Puntospaziale(0, 0, 0, "cursor");
Mouse.hide();
選中第3關(guān)鍵幀,從庫面板中將“Sphere”和“coursor”插入工作區(qū)中,創(chuàng)建相應(yīng)的實例,并分別為其實例命名為“point”和“sphere”,為第3關(guān)鍵幀添加如下ActionScript 腳本:
xrotation = 0.05-(yposition-_ymouse)/400-xrotation/5;
yrotation = (xposition-_xmouse)/400-xrotation/5+0.05;
zrotation = 0.05;
for (var i = 1; i<5; i++) {
eval("miopunto"+i).Rotate(xrotation, yrotation, zrotation);
eval("miopunto"+i).Speed2dx += (_xmouse-eval("miopunto"+i).ScreenCenter_x)/100-eval("miopunto"+i).Speed2dx/10;
eval("miopunto"+i).Speed2dy += (_ymouse-eval("miopunto"+i).ScreenCenter_y)/100-eval("miopunto"+i).Speed2dy/10;
xposition += eval("miopunto"+i).Speed2dx;
yposition += eval("miopunto"+i).Speed2dy;
eval("miopunto"+i).Coord2DRelativeTo(xposition, yposition);
}
miopunto5.x = _xmouse*1.5-450;
miopunto5.y = _ymouse*1.5-300;
depthArray = new Array(5);
for (var k = 1; k<=5; k++) {
depthArray[k-1] = eval("miopunto"+k).z;
}
IndexDepht = OrdIndex(depthArray);
for (var f = 1; f<=5; f++) {
eval("miopunto"+f).DrawPoint(IndexDepht[f-1]);
}
選中第4關(guān)鍵幀,添加如下ActionScript腳本代碼:
gotoAndPlay(3);
6.返回主場景并將默認圖層更名為“電影剪輯”,將“animation”插入工作區(qū)中,將建一圖層“背景”,作矩形工具繪制一矩形,使其將整個工作區(qū)復(fù)蓋,通過“混色器”面板將設(shè)置其填充色如圖1.5所示:
圖1.5 圖設(shè)置填充色
通過填充漸變設(shè)置其填充效果如圖1.6所示:
圖1.6 設(shè)置填充漸變效果
7.這樣整個鼠控效果就制作完成,保存作品,按“ctrl Enter”預(yù)覽最終效果。
------------------------------- · 相關(guān)文檔瀏覽 · --------------------------------------------------------------------- · 熱門文檔瀏覽 · -------------------------------------