0

“ Player.as,第 59 1061 行:通过静态类型 Class 的引用调用可能未定义的方法 hitTestObject。”

我是 Flash 新手,正在尝试制作游戏,特别是我正在尝试制作它,以便游戏中的玩家类可以与事物发生碰撞,我在他的脚底使用了一个正方形(尚未在代码中引用) 和一个名为 collisionTest 的 MovieClip

package
{
    import flash.display.Stage;
    import flash.display.MovieClip;
    import flash.events.Event;
    import KeyObject;

    public class Player extends MovieClip
    {
        public var stageRef:Stage;
        public var key:KeyObject;

        //add these four variables:
        public var leftPressed:Boolean = false; //keeps track of whether the left arrow          key is pressed
        public var rightPressed:Boolean = false; //same, but for right key pressed
        public var upPressed:Boolean = false; //...up key pressed
        public var downPressed:Boolean = false; //...down key pressed

        private var gravity:Number = 2;
        private var runSpeed:Number = 5;

        private var touchingGround:Boolean = false;

        public var vPressed:Boolean = false;

        public function Player(stageRef:Stage, X:int, Y:int):void
        {
            this.stageRef = stageRef;
            this.x = X;
            this.y = Y;

            key = new KeyObject(stageRef);

            addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
        }

        public function loop(e:Event):void
        {
            checkKeypresses(); //call "checkKeypresses()" every frame
            checkCollisions();

            if(leftPressed)
            {
                x -= runSpeed;
            }else if(rightPressed)
            {
                x += runSpeed;
            }
            if(upPressed)
            {
                y -= runSpeed;
            }else if(downPressed)
            {
                y += runSpeed;
            }
        }
        public function checkCollisions():void
        {
**(this is line 59)**           if(Player.hitTestObject(Player.collisionTest)){
                touchingGround = true;
                trace("gounded");
            }
        }

        public function checkKeypresses():void
        {
            // I used http://www.dakmm.com/?p=272 as a reference to get the keyCode numbers for each key
            if(key.isDown(37) || key.isDown(65)){ // if left arrow or A is pressed
                leftPressed = true;
                //trace("left pressed");
            } else {
                leftPressed = false;
            }

            if(key.isDown(38) || key.isDown(87)){ // if up arrow or W is pressed
                upPressed = true;
                //trace("up pressed");
            } else {
                upPressed = false;
            }

            if(key.isDown(39) || key.isDown(68)){ //if right arrow or D is pressed
                rightPressed = true;
                //trace("right pressed");
            } else {
                rightPressed = false;
            }

            if(key.isDown(40) || key.isDown(83)){ //if down arrow or S is pressed
                downPressed = true;
                //trace("down pressed");
            } else {
                downPressed = false;
            }
        }
    }
}
4

1 回答 1

4

函数 hitTestObject 不是静态函数,因此您应该从对象实例调用它,与碰撞测试相同。

所以应该是

this.hitTestObject(collisionTest);//set collisionTest in the Player class
于 2013-09-04T03:35:56.157 回答