Javascript:Jump n Run->函数跳转()

时间:2017-01-26 12:36:06

标签: javascript html

我的问题:Chrome调试器在尝试运行函数jump()时显示错误消息,说“jump()不是函数”。第一次调用jump()时才会发生这种情况。我肯定定义了函数jump(),因此不明白为什么会出现这个错误。有人可以帮帮我吗?

    var yVel = 2; //Velocity in the Y Direction (top)
    var jumpHigh = 230;
    var isJumping = false; //Saves the state if the character is jumping or not - prevent multiple jumps
    var drop;
    var jump;
    var realJumpHigh = obj_top-jumpHigh;
    var z = 0;                                  //Counter
    var i = 2;
    var lock = true;
    function jump() 
    {
        setPos(obj_top, obj_left);
        //If the character isn't already jumping - jump
        if (isJumping == false) jump = setInterval(jumpUp,10);
    }
    function jumpUp() {
        obj_top -= yVel;
        setPos(obj_top,obj_left);
        z++;
        if(z == 90) yVel = yVel/i;
        if(z == 120) yVel = yVel/i;
        if(z == 140) yVel = yVel/i;

        //Check if the character has reached the ground the drop is stopped
        if (obj_top < realJumpHigh){                
            obj_top = realJumpHigh;
            setPos(obj_top,obj_left);
            yVel = 0.25;
            z = 0;
            clearInterval(jump);
            isJumping = true;
            droploop();
            }
    }

    /* The aim of the function droploop is the slow descent of the character after the Jump */
    function droploop()
    {
        //if isJumping is true
        if(isJumping) 
        {
            if(lock){
                drop = setInterval(droploop,10);
                lock = false;
            }
            obj_top += yVel;
            setPos(obj_top,obj_left);
            z++;
            if(z == 20) yVel = yVel*i;
            if(z == 10) yVel = yVel*i;
            if(z == 5) yVel = yVel*i;
            //Check if the character has reached the ground the drop is stopped
            if (obj_top > characterGround){             
                obj_top = characterGround;
                setPos(obj_top,obj_left);
                yVel = 2;
                z = 0;
                clearInterval(drop);
                isJumping = false;
                lock = true;
            }
        }
    }

0 个答案:

没有答案