0

我正在为我的新项目使用 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 代码

4

2 回答 2

1

问题出在你的update()功能上。您需要先super.update()致电FlxG.collide()

override public function update():void
{
    super.update();
    FlxG.collide(player, level);
}
于 2012-05-05T19:30:51.437 回答
0

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

您告诉 FlxControl 仅在触摸 FLOOR 类型的 FlxObject 时让玩家跳跃。玩家是否站在允许碰撞设置为 FLOOR 或 ANY 的对象上?

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

    /**
     * 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
于 2012-05-05T14:41:02.160 回答