2011年6月4日 星期六

捲筒式選單



雖然可能不是很實用,但是效果應該還不錯。

程式碼還蠻長的,所以只講重點囉。
首先是Initialization

畢竟計算3D的座標也是要靠CPU下去算,如果直接讓電腦算的話雖然會比較省事,但是效能會拖慢。

所以首先始先把座標遇先算好。
private function init():void {
    var theta:Number;
    for (var i:int = 0; i < 360; i++){
        theta = i * Math.PI / 180;
        var p:* = {  x: Math.cos(theta) * WIDTH_FIT, //預先算好360度的 x,y,z
                            y: Math.cos(theta) * HEIGHT_FIT,
                            z: Math.sin(theta) * HEIGHT_FIT,
                            rotationX: i + 90, //橫向時所需的旋轉角度
                            rotationY: -i - 90, //縱向時所需的旋轉角度
                            alpha: .6,    //滑鼠不在按鈕上時的alpha值
                            Alpha: 0.2 + (((HEIGHT_FIT - (Math.sin(theta) * HEIGHT_FIT)) / HEIGHT_FIT) * 0.5)}; //Button內層顏色的透明度,這裡是為了突顯3D效果
        position.push(p);
    }
}
座標算好之後就是產生按鈕 程式碼如下
private function BUTTON(theta:int,w:Number = 256, h:Number = 64, text:String = "123", textColor:uint = 0, color:uint = 0x33CC66, alpha:Number = 1):Button {
    var button:Button = new Button(w, h, text, textColor, color, alpha);
    _objects.push(button);
    button.index = (360 - theta + 269 + Shift) % 360;
    //直接把剛剛init產生出來的值填進去
    for (var str:String in position[button.index])
        if (ScrollMode == 'y'){
            if (str != 'x' && str != 'rotationY')
                button[str] = position[button.index][str];
        }else if (ScrollMode == 'x'){
                if (str != 'y' && str != 'rotationX')
                    button[str] = position[button.index][str];
            }
    button.addEventListener(MouseEvent.MOUSE_OUT, Move);
    Mouse.add(button, MouseEvent.MOUSE_OUT, {alpha: .6, filters: []}); //這個類就暫時先不提(要引入package.swc  因為蠻複雜的..以後再做整理),效果就是跟addEventListener一樣
    Mouse.add(button, MouseEvent.MOUSE_OVER, { alpha: .9, filters: [new GlowFilter(0xffffff, 0.9, 32, 32, 2)] } );
    return button;
}
其中有一個Mouse的類別,這是我為了方便製作按鈕而寫的類別。
但是因為實在是非常的複雜,而且還在建構中,尚不完全。
先附上swc檔,日後再做解說。
程式的重點大致上就這些,再來就是應用了。附上完整程式碼,有問題在留言吧。

沒有留言:

張貼留言