簡體   English   中英

AS3 加速度計和風運動

[英]AS3 Accelerometer & Wind Movement

我正在使用標准加速度計模板並試圖在球上創建風效果,但是我無法讓我的編碼風移動球,因為球似乎只響應加速度計運動。

有沒有辦法在不禁用加速度計的情況下移動球?

我已經設置了風向和強度,但是當我測試時,即使屏幕是平的並且球在屏幕中心,風變量/代碼也沒有影響。

我正在使用的風移動球功能的一個例子是

        if (windD == "left")
            {ball.x -= ball.x-WindStrength;}
        if (windD == "right")
            {ball.x += ball.x+WindStrength;}

有任何想法嗎。

好的,我想通了。

我的問題是我試圖在加速度計運動功能之外的自己的功能中添加風運動功能。

解決方案:是將我的風代碼移動到加速計功能中:

ball.addEventListener(Event.ENTER_FRAME, moveBall);
function moveBall(evt:Event){
ball.x -= accelX*10;
ball.y += accelY*10;

if(ball.x > (480-ball.width/2)){
    ball.x = 480-ball.width/2;
}
if(ball.x < (0+ball.width/2)){
    ball.x = 0+ball.width/2;
}
if(ball.y > (800-ball.width/2)){
   ball.y = 800-ball.width/2;
}
if(ball.y < (0+ball.width/2)){
    ball.y = 0+ball.width/2;
}

  // Wind Functions
   //Wind Strength
    if (this.Stage_Txt_Box.text == "1")
            {WindStrength = int(2);}
    if (this.Stage_Txt_Box.text == "2")
            {WindStrength = int(3);}
    if (this.Stage_Txt_Box.text == "3")
            {WindStrength = int(4);}
    if (this.Stage_Txt_Box.text == "4")
            {WindStrength = int(5);}    
    if (this.Stage_Txt_Box.text == "5")
            {WindStrength = int(6);}
    if (this.Stage_Txt_Box.text == "6")
            {WindStrength = int(7);}
        if (this.Stage_Txt_Box.text == "7")
            {WindStrength = int(8);}
        if (this.Stage_Txt_Box.text == "8")
            {WindStrength = int(9);}            

        //Wind Directions
        trace(WindStrength);

        if (windD == "left")
            {ball.x -= WindStrength; trace("Wind is blowing left");}
        if (windD == "right")
            {ball.x += WindStrength; trace("Wind is blowing right");}
        if (windD == "up")
            {ball.y -= WindStrength; trace("Wind is blowing up");}
        if (windD == "down")
            {ball.y += WindStrength; trace("Wind is blowing down");}    
     }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM