-1

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

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

我已经设置了风向和强度,但是当我测试即使屏幕是平的并且球在屏幕中心时,风变量/代码也没有效果。

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

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

有任何想法吗。

4

1 回答 1

0

好的,我想通了。

我的问题是我试图在加速度计运动功能之外的自身功能中添加风运动功能。

解决方案:是将我的风代码移动到加速度计功能中:

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");}    
     }
于 2018-02-16T14:44:06.007 回答