if (FlxG.keys.anyPressed(["S"])) { animation.play("crouch");}if (FlxG.keys.pressed.S)
if (FlxG.keys.justPressed.S)
if (FlxG.keys.justReleased.S)
package ;import flixel.FlxG;import flixel.FlxSprite;import flixel.FlxObject;import flixel.input.keyboard.FlxKey;import flixel.input.keyboard.FlxKeyboard;import flixel.util.FlxPoint;import flixel.tile.FlxTilemap;
class Player extends FlxSprite{ private var jumpPower:Int = 900; public var player:FlxSprite; private var jumplimit:Int = 0; private var punchlimit:Int = 0; private var crouching:Bool; private var crouch:Int = 0; private var S:Bool; public function new(inX:Int, InY:Int) { super(inX, InY); loadGraphic("assets/images/Spar1.png", true, 20, 35); width = 8; height = 20; offset = new FlxPoint(5, 1); acceleration.y = 1000; maxVelocity.set(200, 200); drag.set(800, 800); animation.add("Running", [0, 1, 2, 3, 4, 5], 7, true); animation.add("Idle", [0]); animation.add("Jump", [8]); animation.add("Fall", [9]); animation.add("punch", [10, 11, 12, ], 7); animation.add("crouch", [13, 14, 15], 10,false); setFacingFlip(FlxObject.RIGHT, false, false); setFacingFlip(FlxObject.LEFT, true, false); } override public function update():Void { acceleration.x = 0; if (velocity.x == 0) { animation.play("Idle"); } if (FlxG.keys.anyPressed(["LEFT", "A"])) { acceleration.x = -800; facing = FlxObject.LEFT; animation.play("Running"); } else if (FlxG.keys.anyPressed(["RIGHT", "D"])) { acceleration.x = 800; facing = FlxObject.RIGHT; animation.play("Running"); } if (!FlxG.keys.anyJustPressed(["W", "UP"]) && velocity.y == 0 ){ jumplimit = 0; } if (FlxG.keys.anyJustPressed(["W", "UP"]) && jumplimit < 2 ) { /*trace("jump");*/ jumplimit++; velocity.y = -jumpPower; } if (velocity.y < 0) { animation.play("Jump"); }else if (velocity.y > 0) { animation.play("Fall"); } if (FlxG.keys.anyPressed(["E"]) ){ animation.play("punch"); } super.update(); } }Enter code here...package ;import flixel.FlxG;import flixel.FlxSprite;import flixel.FlxObject;import flixel.input.keyboard.FlxKey;import flixel.input.keyboard.FlxKeyboard;import flixel.util.FlxPoint;import flixel.tile.FlxTilemap;
class Player extends FlxSprite{ private var jumpPower:Int = 900; public var player:FlxSprite; private var jumplimit:Int = 0; private var punchlimit:Int = 0; private var punching:Bool = false; private var jumping:Bool = false; private var crouching:Bool; private var crouch:Int = 0; private var S:Bool; private var F:Bool; private var crouchi:Bool = false; private var sprinting:Bool; private var crouchmoving:Bool = false; public function new(inX:Int, InY:Int) { super(inX, InY); loadGraphic("assets/images/Spar1.png", true, 20, 35); width = 8; height = 20; offset = new FlxPoint(5, 1); acceleration.y = 1000; maxVelocity.set(200, 200); drag.set(800, 800); animation.add("Running", [0, 1, 2, 3, 4, 5], 7, true); animation.add("Idle", [0]); animation.add("Jump", [8]); animation.add("Fall", [9]); animation.add("punch", [10, 11, 12,0 ], 7, false); animation.add("crouch1", [13, 14], 1, false); animation.add("crouch", [13, 14, 15], 10,true); animation.add("movingwCrouch",[24, 25, 26, 27], 6, true); animation.add("sprint", [20, 21, 22, 23], 9, true); animation.add("crouch3", [15]); setFacingFlip(FlxObject.RIGHT, false, false); setFacingFlip(FlxObject.LEFT, true, false); animation.callback = animationCallback; FlxG.watch.add(this, "punching"); } override public function update():Void { acceleration.x = 0; if (!FlxG.keys.pressed.SHIFT) { sprinting = false; } if (FlxG.keys.pressed.SHIFT) { sprinting = true; } if (velocity.x == 0 && !punching) { animation.play("Idle"); } if (FlxG.keys.anyPressed(["LEFT", "A"])) { acceleration.x = -800; facing = FlxObject.LEFT; animation.play("Running"); crouchmoving = true; } else if (FlxG.keys.anyPressed(["RIGHT", "D"])) { acceleration.x = 800; facing = FlxObject.RIGHT; animation.play("Running"); crouchmoving = true; } if (FlxG.keys.pressed.A && sprinting == true) { velocity.x = -450; animation.play("sprint"); } else if (FlxG.keys.pressed.D && sprinting == true) { velocity.x = 450; animation.play("sprint"); } if (!FlxG.keys.anyJustPressed(["SPACE"]) && velocity.y == 0 ){ jumplimit = 0; jumping = false; } if (FlxG.keys.anyJustPressed(["SPACE"]) && jumplimit < 2 ) { /*trace("jump");*/ jumping = true; jumplimit++; velocity.y = -jumpPower; } if (velocity.y < 0) { animation.play("Jump"); } else if (velocity.y > 0) { animation.play("Fall"); } if (FlxG.keys.justPressed.E) { animation.play("punch"); punching = true; } if (FlxG.keys.pressed.S && velocity.x == 0 ) { crouchi = true; animation.play("crouch3"); } if (FlxG.keys.pressed.S && crouchmoving == true && velocity.x != 0) { animation.play("movingwCrouch"); } else if (FlxG.keys.pressed.S && crouchmoving == true && velocity.x != 0) { animation.play("movingwCrouch"); } super.update(); }
function animationCallback(name:String, frame:Int, frameIndex:Int):Void { FlxG.watch.addQuick("current anim", name); FlxG.watch.addQuick("current frame", frame); punching = (name == "punch" && !animation.curAnim.finished); }