2009-12-11 34 views
1

嗨我有一個as3文件(下面列出),當鼠標懸停在它上面(使用Tweenlight)時,它只是沿着X軸移動一個盒子。我想要做的是把盒子放在30度的角度上,讓盒子沿着這個角度移動。有人可以告訴我我做錯了嗎?Flash AS3在一個角度補間

import com.greensock.*; 
import com.greensock.easing.* ; 


cont.addEventListener(MouseEvent.ROLL_OVER, onOver); 
cont.addEventListener(MouseEvent.ROLL_OUT, onOut); 
var stx:Number; 

function onOver(e:MouseEvent):void 
{ 
    var stx:Number = cont.x +20 ; 

    TweenLite.to(cont, 1, { x:stx }); 
} 

function onOut(e:MouseEvent):void 
{ 
    stx = cont.x - 20 
    TweenLite.to(cont, 1, { x:stx }); 
} 

這裏是活生生的例子:http://img42.imageshack.us/i/box.swf/

回答

3

最困難的事情是在一個30度角移動你的盒子上線。 你將不得不使用Trigonometry ...記住SOHCAHTOA?

所以基本上你需要在x和y方向上移動。

在你onOver處理器...

要移動X到20 * Math.cos(30 * Math.PI/180)

你想爲y移動到20 * Math.sin (30 * Math.PI/180)

cos和sin爲您提供x和y步驟,以保持物體沿30度移動。

如果您希望您的對象移動更多,請更改20參數。