You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are many ways to implement a jumping mechanic, but the simplest method is to add negative <var>y</var> {% api flixel.FlxObject.velocity %} temporarily to a {% api flixel.FlxObject %} with positive <var>y</var> {% api flixel.FlxObject.acceleration %}, using some kind of timer to limit the jump time.
9
+
There are many ways to implement a jumping mechanic, but the simplest method is to add negative <var>y</var> {% api flixel.FlxObject.velocity %} temporarily to a {% api flixel.FlxObject %} with positive <var>y</var> {% api flixel.FlxObject.acceleration %}.
10
10
11
11
12
12
```haxe
13
-
FlxG.collide(box, sprite);
14
-
15
-
var jumpPressed:Bool = pad.buttonA.pressed;
16
-
17
-
if (jumping && !jumpPressed)
18
-
jumping = false;
13
+
// call super.update first, as it sets touching flags to NONE
14
+
super.update(elapsed);
19
15
20
-
/*
21
-
* Reset jumpTimer when touching the floor
22
-
* Note: This sprite's touching flags are set via FlxG.collide,
23
-
* and are reset to false on super.update
24
-
*/
25
-
if (sprite.isTouching(DOWN) && !jumping)
26
-
jumpTimer = 0;
27
-
28
-
if (jumpTimer >= 0 && jumpPressed)
29
-
{
30
-
jumping = true;
31
-
jumpTimer += elapsed;
32
-
}
33
-
else
34
-
jumpTimer = -1;
16
+
// If sprite is resting on box it will set its touching to DOWN
17
+
FlxG.collide(box, sprite);
35
18
36
-
// hold button to jump higher (up to 0.25s)
37
-
if (jumpTimer > 0 && jumpTimer < 0.25)
19
+
// jump if touching the box, and jump is pressed
20
+
if (sprite.isTouching(DOWN) && !pad.buttonA.pressed)
A more advanced jumping technique is to allow the object to jump higher if the button held, there's multiple ways to achieve this, but one common way it maintain the jump velocity for a brief time, so long as the button is held.
10
+
11
+
```haxe
12
+
// call super.update first, as it sets touching flags to NONE
13
+
super.update(elapsed);
14
+
15
+
// If sprite is resting on box it will set its touching to DOWN
16
+
FlxG.collide(box, sprite);
17
+
18
+
// Reset jumpTimer when touching the floor and jump is pressed
19
+
if (sprite.isTouching(DOWN) && pad.buttonA.justPressed)
0 commit comments