AS3加速度计&风运动

时间:2018-02-16 07:29:29

标签: actionscript-3 flash adobe-animate

我正在使用标准的Accelerometer模板&我试图在球上创造一个风效果,但是我无法让我的编码风移动球,因为球似乎只响应加速度计的运动。

有没有办法在不禁用加速度计的情况下移动球?

我已设置风向&力量,但是当我测试时,即使屏幕是平的&球在屏幕中心,风变量/代码没有效果。

我正在使用的风移动球功能的一个例子是

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

任何想法。

1 个答案:

答案 0 :(得分:0)

好的,我明白了。

我的问题是我试图在Accellerometer运动功能之外的自己的功能中添加风运动功能。

解决方案:将我的风码移动到accellerometer功能中:

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");}    
     }