0

I'm using Flixel Power Tools for my new project, to be specific I'm using FlxControl.
I tried to set a Jump button using FlxControl.player1.setJumpButton(), but it does not work.
I tried using it like this:

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);

Note:The arrow keys(left & right) are working as expected.
Edit:
Full PlayState.as code at github.com : Github PlayState.as code

Machavity
  • 30,841
  • 27
  • 92
  • 100
Abdulaziz
  • 2,201
  • 1
  • 21
  • 35

2 Answers2

1

The problem is in your update() function. You need to call super.update() before FlxG.collide():

override public function update():void
{
    super.update();
    FlxG.collide(player, level);
}
Charles Menguy
  • 40,830
  • 17
  • 95
  • 117
Scrittl
  • 26
  • 1
  • ok..I cant really explain that, 2 days of searching, debugging, asking just because of this? Actually that's the first thing I learned about flixel, Thanks pal! – Abdulaziz May 05 '12 at 19:51
  • The super.update() calls update() on all added objects. (including your player).And as an extended FlxObject the player object gets a call to .postUpdate(). -> "touching" is set to "none". Inside "collide" your player gets the flag that he is touching the ground (which would allow him to jump), but immediatelly after that you call super.update and reset that touching flag to none again. – Scrittl May 05 '12 at 20:08
0

The code you posted looks fine. My guess is that the problem lies with the platform you are trying to jump off of. To know for sure I would have to see the code where you create your platforms.

You told FlxControl to only let the player jump when touching an FlxObject of type FLOOR. Is the player standing on an object that has allowCollisions set to either FLOOR or ANY?

Relevant documentation (see "surface" parameter):

    /**
     * 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
WgFunstorm
  • 148
  • 1
  • 10