FlxControl.player1.setJumpButton无法按预期工作

时间:2012-05-05 12:53:33

标签: actionscript-3 flash actionscript flixel

我正在为我的新项目使用Flixel Power Tools,具体来说我正在使用FlxControl
我尝试使用FlxControl.player1.setJumpButton()设置跳转按钮,但它不起作用 我尝试过这样使用它:

player = new FlxSprite(FlxG.width/2 - 5);
            player.makeGraphic(10,12,0xffaa1111);
            add(player);
            if (FlxG.getPlugin(FlxControl) == null)
            {
                FlxG.addPlugin(new FlxControl);
            }

            FlxControl.create(player, FlxControlHandler.MOVEMENT_ACCELERATES, FlxControlHandler.STOPPING_DECELERATES, 1, true, false);

            FlxControl.player1.setCursorControl(false, false, true, true);

            FlxControl.player1.setJumpButton("SPACE", FlxControlHandler.KEYMODE_PRESSED, 200, FlxObject.FLOOR, 250, 200);

            FlxControl.player1.setBounds(16, 0, 288, 240);

            FlxControl.player1.setMovementSpeed(400, 0, 100, 200, 400, 0);

            FlxControl.player1.setGravity(0, 400);

注意:箭头键(左侧和右侧)按预期工作 编辑:
github.com上的完整PlayState.as代码:Github PlayState.as code

2 个答案:

答案 0 :(得分:1)

问题出在您的update()功能中。您需要在super.update()之前致电FlxG.collide()

override public function update():void
{
    super.update();
    FlxG.collide(player, level);
}

答案 1 :(得分:0)

您发布的代码看起来不错。我的猜测是问题在于你试图跳出的平台。要确定我必须看到您创建平台的代码。

你告诉FlxControl只让玩家在触摸FLOOR类型的FlxObject时跳转。玩家是否站在允许将玩家设置为FLOOR或ANY?的对象上?

相关文档(参见“surface”参数):

    /**
     * Enable a jump button
     * 
     * @param   key             The key to use as the jump button (String from org.flixel.system.input.Keyboard, i.e. "SPACE", "CONTROL")
     * @param   keymode         The FlxControlHandler KEYMODE value (KEYMODE_PRESSED, KEYMODE_JUST_DOWN, KEYMODE_RELEASED)
     * @param   height          The height in pixels/sec that the Sprite will attempt to jump (gravity and acceleration can influence this actual height obtained)
     * @param   surface         A bitwise combination of all valid surfaces the Sprite can jump off (from FlxObject, such as FlxObject.FLOOR)
     * @param   repeatDelay     Time delay in ms between which the jumping can repeat (250 would be 4 times per second)
     * @param   jumpFromFall    A time in ms that allows the Sprite to still jump even if it's just fallen off a platform, if still within ths time limit
     * @param   callback        A user defined function to call when the Sprite jumps
     * @param   altKey          Specify an alternative jump key that works AS WELL AS the primary jump key (TODO)
     */
    public function setJumpButton(key:String, keymode:uint, height:int, surface:int, repeatDelay:uint = 250, jumpFromFall:int = 0, callback:Function = null, altKey:String = ""):void