1067:将Function类型的值隐式强制转换为不相关的类型Number

时间:2013-09-21 09:08:57

标签: function actionscript numbers pythagorean

我从这两行获得了两次错误

var dx = Math.cos(deg2rad(playerRocket.rotation)) * playerThrustPower;
var dy = Math.sin(deg2rad(playerRocket.rotation)) * playerThrustPower;

我似乎无法弄清楚问题,我暂时没有使用Actionscript,请原谅“noob-ness”

编辑:这是我的程序的所有代码。到目前为止只有两个动画片段,火箭和一个儿童动画片段,它只是一个从火箭中出来的火焰,只有在按住鼠标左键时才能看到它

//Math Variables
var radiance:Number = 180/Math.PI;

//Keydown variables
var leftClicked = false;

//More Variables
var playerRMouseDist:Number = 0;

//player properties variables
var playerThrust = false;

stage.addEventListener(Event.ENTER_FRAME, onFrame);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mousePress);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseRelease);

function onFrame(Event):void
{
    movePlayerRocket();
    root.scrollRect = new Rectangle(playerRocket.x - stage.stageWidth/2, playerRocket.y - stage.stageHeight/2, stage.stageWidth, stage.stageHeight);
    checkPresses();
}

function mousePress(MouseEvent):void
{
        leftClicked = true; 
}

function mouseRelease(MouseEvent):void
{
        leftClicked = false; 
}

function checkPresses():void
{
    if(leftClicked)
    {
        playerThrustOn();
    }
    else
    {
        playerThrustOff();
    }
}

function playerThrustOn():void
{
    playerThrust = true;
}

function playerThrustOff():void
{
    playerThrust = false;
}

function getAngle(x1:Number, y1:Number, x2:Number, y2:Number):Number {
    var radians:Number = Math.atan2(y2 - y1, x2 - x1);
    return rad2deg(radians);
}

function getDistance(x1:Number, y1:Number, x2:Number, y2:Number):Number
{
    var dx:Number = x2 - x1;
    var dy:Number = y2 - y1;
    return Math.sqrt(dx * dx + dy * dy);
}

function rad2deg(rad:Number):Number {
    return rad * (180 / Math.PI);
}

function deg2rad(deg:Number):Number {
    return deg * (Math.PI/180);
}

function movePlayerRocket():void
{
    rotatePlayerRocket();
    playerThrustPower();
    playerRMouseDist = getDistance(mouseX,mouseY,playerRocket.x,playerRocket.y);

    if(playerThrust)
    {
        playerRocket.playerThrustFlame.visible = true;
    }
    else
    {
        playerRocket.playerThrustFlame.visible = false;
    }

        var dx = Math.cos(deg2rad(playerRocket.rotation)) * playerThrustPower;
        var dy = Math.sin(deg2rad(playerRocket.rotation)) * playerThrustPower;
        playerRocket.x += dx;
    playerRocket.y += dy;
}

function playerThrustPower():void
{
        var playerThrustPower:Number = playerRMouseDist/8;
        playerRocket.playerThrustFlame.width = playerThrustPower;
        playerRocket.playerThrustFlame.height = playerThrustPower;
}

function rotatePlayerRocket():void
{
        var walkdirection = -(Math.atan2(mouseX-playerRocket.x, mouseY-playerRocket.y))*radiance;
        playerRocket.rotation = walkdirection;
}

0 个答案:

没有答案