Skip to content

Commit ec2f21b

Browse files
authored
Add Group collision + various changes (#46)
* fix fonts CI * remove hxproj files * cleanup * add group overlap snippet * avoid the word fonts altogether * formatting+bgcolor * change all cameras * remove public from overrides
1 parent 756108a commit ec2f21b

File tree

111 files changed

+774
-2730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+774
-2730
lines changed

_proofs/overlap/group-overlap.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Group Overlap
3+
concept: Overlap
4+
order: 1
5+
tags: [overlap]
6+
complexity: 1
7+
sourcefiles: source/PlayState.hx
8+
seealso: [Collision/1-to-1-collision]
9+
---
10+
{% api flixel.FlxG.overlap() %} not only works between 2 {% api flixel.FlxObject %}s, but you can also pass in a {% api flixel.group.FlxGroup %} to either arg.
11+
12+
{% api flixel.FlxG.overlap() %} will still return whether it detected any overlap between the groups, but it is usually wise to use a `notifyCallback` to handle each specific overlap.
13+
14+
## Performance
15+
{% api flixel.FlxG.overlap() %} uses quadtrees on groups to greatly reduce the number of comparisons between objects, meaning that a single call with 2 groups can perform immensely better than checking whether each pair of objects overlaps, individually.
16+
17+
```haxe
18+
function handleCollision(objA:FlxObject, objB:FlxObject)
19+
{
20+
trace('overlap between a: $objA and b:$objB');
21+
}
22+
23+
// check if any objects in groupA overlap any objects in groupB
24+
FlxG.overlap(groupA, groupB, handleCollision);
25+
// check if the player overlaps anything in groupB
26+
FlxG.overlap(player, groupB, handleCollision);
27+
// Chech if any objects in groupA overlap each other
28+
FlxG.overlap(groupA, groupA, handleCollision);
29+
```

demos/advanced/timescale/source/PlayState.hx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@ import flixel.util.FlxColor;
1111
class PlayState extends FlxState
1212
{
1313
private var statusText:FlxText;
14-
15-
override public function create()
14+
15+
override function create()
1616
{
17-
bgColor = 0;
18-
17+
super.create();
18+
1919
var sprite:FlxSprite = new FlxSprite();
2020
sprite.loadGraphic("assets/anim-sprite.png", true, 24, 24);
2121
var animationFrames = [1, 2, 3, 4, 5, 6].concat([for (i in 0...20) 0]);
2222
sprite.animation.add("shine", animationFrames, 15);
2323
sprite.animation.play("shine");
2424
add(sprite);
25-
26-
FlxTween.circularMotion(sprite, FlxG.width / 2, FlxG.height / 2, FlxG.width / 4, 0, true,
27-
2, true, {
28-
type: FlxTweenType.LOOPING
29-
});
30-
25+
26+
FlxTween.circularMotion(sprite, FlxG.width / 2, FlxG.height / 2, FlxG.width / 4, 0, true, 2, true, {
27+
type: FlxTweenType.LOOPING
28+
});
29+
3130
statusText = new FlxText();
3231
statusText.size = 16;
3332
statusText.text = "timeScale: 1";
@@ -39,12 +38,10 @@ class PlayState extends FlxState
3938
statusText.alignment = FlxTextAlign.LEFT;
4039
statusText.x = statusText.y = 10;
4140
add(statusText);
42-
41+
4342
FlxTween.num(.05, 2, 5, {type: FlxTweenType.PINGPONG}, updateTimeScale);
44-
45-
super.create();
4643
}
47-
44+
4845
private function updateTimeScale(Value:Float):Void
4946
{
5047
FlxG.timeScale = Value;

demos/basics/adding/adding.hxproj

Lines changed: 0 additions & 57 deletions
This file was deleted.

demos/basics/adding/source/PlayState.hx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ import flixel.FlxState;
66

77
class PlayState extends FlxState
88
{
9-
override public function create()
9+
override function create()
1010
{
11-
bgColor = 0;
12-
13-
super.create();
14-
11+
super.create();
12+
1513
var box = new FlxSprite("assets/bigbox.png");
1614
box.screenCenter();
17-
15+
1816
var sprite = new FlxSprite("assets/sprite.png");
1917
sprite.screenCenter();
20-
18+
2119
add(box);
2220
add(sprite);
2321
}

demos/basics/screen/source/PlayState.hx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ import flixel.text.FlxText;
66

77
class PlayState extends FlxState
88
{
9-
override public function create()
9+
override function create()
1010
{
11-
bgColor = 0;
12-
1311
super.create();
14-
15-
var text = new FlxText(0, 0, FlxG.width,
16-
"The Screen's dimensions\nare " + FlxG.width + "x" + FlxG.height + " pixels", 12);
17-
12+
13+
var text = new FlxText(0, 0, FlxG.width, "The Screen's dimensions\nare " + FlxG.width + "x" + FlxG.height + " pixels", 12);
14+
1815
text.color = 0xff000000;
1916
text.alignment = FlxTextAlign.CENTER;
2017
text.setBorderStyle(FlxTextBorderStyle.SHADOW, 0xFF808080);

demos/camera/fade/fade.hxproj

Lines changed: 0 additions & 57 deletions
This file was deleted.

demos/camera/fade/source/PlayState.hx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@ class PlayState extends FlxState
99
var timer:Float = 0;
1010
var direction:Bool = false;
1111
var color:FlxColor;
12-
13-
override public function create()
14-
{
15-
bgColor = 0;
16-
17-
super.create();
18-
}
19-
20-
override public function update(elapsed:Float)
12+
13+
override function update(elapsed:Float)
2114
{
15+
super.update(elapsed);
16+
2217
timer -= elapsed;
2318
if (timer <= 0)
2419
{
@@ -30,7 +25,5 @@ super.create();
3025
FlxG.camera.fade(color, 1, direction, null, true);
3126
direction = !direction;
3227
}
33-
34-
super.update(elapsed);
3528
}
3629
}

demos/camera/flash/flash.hxproj

Lines changed: 0 additions & 57 deletions
This file was deleted.

demos/camera/flash/source/PlayState.hx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,16 @@ import flixel.util.FlxColor;
77
class PlayState extends FlxState
88
{
99
var timer:Float = 2;
10-
11-
override public function create()
12-
{
13-
bgColor = 0;
14-
15-
super.create();
16-
}
17-
18-
override public function update(elapsed:Float)
10+
11+
override function update(elapsed:Float)
1912
{
2013
timer -= elapsed;
2114
if (timer <= 0)
2215
{
2316
timer = 2;
2417
FlxG.camera.flash(FlxColor.fromHSB(FlxG.random.int(0, 360), 1, 1));
2518
}
26-
19+
2720
super.update(elapsed);
2821
}
2922
}

0 commit comments

Comments
 (0)