Jump function not working...
-
Hi again,
as my time with haxeflixel is going, I am trying to make a jump possible, while the left and right movemet works, for some reason the jumping section is not working, I tried to watch the bool in the debugger and it seems to pass true while I press the key but it stills does not work, any help will be most welcome.
here is the player code:
package; import flixel.FlxSprite; import flixel.FlxG; import flixel.util.FlxColor; class Player extends FlxSprite { var _left:Bool; var _right:Bool; var _jump:Bool; public static inline var speed:Float = 30; public static inline var gravity:Float = 800; public static inline var jumpSpeed = 250; public var climbing:Bool = false; private var onLadder:Bool = false; public function new() { super(); makeGraphic(16, 16, FlxColor.RED); drag.x = drag.y = 1000; maxVelocity.x =maxVelocity.y = 150; acceleration.y = gravity; } override public function update(elapsed:Float):Void { super.update(elapsed); //acceleration.x = 0; Movement(); } private function Movement():Void { _left = FlxG.keys.anyPressed(["LEFT", "A"]); _right = FlxG.keys.anyPressed(["RIGHT", "D"]); _jump = FlxG.keys.anyPressed(["W", "SPACE", "UP"]); if (_left && _right) { _left = _right = false; } if (_right) { velocity.x += speed; } if (_left) { velocity.x -= speed; } if (_jump) { velocity.y -= jumpSpeed; } } }
-
What I did to fix it was call Movement(); before super.update(); , and that seemed to fix the jumps
override public function update(elapsed:Float):Void { Movement(); super.update(elapsed); }
This has a bit mroe info about super.update
https://github.com/AdamAtomic/flixel/wiki/Flixel-Cheat-Sheet-1:-The-Basics#why-isnt-anything-happening