Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/bridge_packages/flame_behaviors/collision-detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MyEntityCollisionBehavior
extends CollisionBehavior<MyCollidingEntity, MyParentEntity> {
@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
MyCollidingEntity other,
) {
// We are starting colliding with MyCollidingEntity
Expand Down
8 changes: 4 additions & 4 deletions doc/flame/collision_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Example:
```dart
class MyCollidable extends PositionComponent with CollisionCallbacks {
@override
void onCollision(Set<Vector2> points, PositionComponent other) {
void onCollision(List<Vector2> points, PositionComponent other) {
if (other is ScreenHitbox) {
//...
} else if (other is YourOtherComponent) {
Expand All @@ -101,7 +101,7 @@ class MyCollidable extends PositionComponent with CollisionCallbacks {
```

In this example we use Dart's `is` keyword to check what kind of component we collided with.
The set of points is where the edges of the hitboxes intersect.
The list of points is where the edges of the hitboxes intersect.

Note that the `onCollision` method will be called on both `PositionComponent`s if they have both
implemented the `onCollision` method, and also on both hitboxes. The same goes for the
Expand Down Expand Up @@ -137,7 +137,7 @@ save all the other `PositionComponent`s to this list:

```dart
@override
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
void onCollision(List<Vector2> intersectionPoints, PositionComponent other) {
collisionComponents.add(other);
super.onCollision(intersectionPoints, other);
}
Expand Down Expand Up @@ -395,7 +395,7 @@ class Bullet extends PositionComponent with CollisionCallbacks {

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
// Removes the component when it comes in contact with a Brick.
Expand Down
2 changes: 1 addition & 1 deletion doc/flame/examples/lib/collision_detection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RectangleCollidable extends PositionComponent with CollisionCallbacks {

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
2 changes: 1 addition & 1 deletion doc/flame/other/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class Bullet extends SpriteComponent with CollisionCallbacks {
}

@override
void onCollisionStart(Set<Vector2> points, PositionComponent other) {
void onCollisionStart(List<Vector2> points, PositionComponent other) {
super.onCollisionStart(points, other);
// Return to pool on collision. No manual release needed.
removeFromParent();
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/platformer/app/lib/actors/ember.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class EmberPlayer extends SpriteAnimationComponent
}

@override
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
void onCollision(List<Vector2> intersectionPoints, PositionComponent other) {
if (other is GroundBlock || other is PlatformBlock) {
if (intersectionPoints.length == 2) {
// Calculate the collision normal and separation distance.
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/platformer/step_5.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Now add the following `onCollision` method:

```dart
@override
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
void onCollision(List<Vector2> intersectionPoints, PositionComponent other) {
if (other is GroundBlock || other is PlatformBlock) {
if (intersectionPoints.length == 2) {
// Calculate the collision normal and separation distance.
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/space_shooter/app/lib/step6/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class Enemy extends SpriteAnimationComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorials/space_shooter/step_6.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Enemy extends SpriteAnimationComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down Expand Up @@ -148,7 +148,7 @@ in order to add the explosion to the game:
```dart
@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TheBall extends PositionComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BulletComponent extends SpriteAnimationComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PlayerComponent extends SpriteAnimationComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
2 changes: 1 addition & 1 deletion examples/games/trex/lib/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Player extends SpriteAnimationGroupComponent<PlayerState>

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MovableEmber extends Ember<FollowComponentExample>

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Ball extends CircleComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class MyCollidable extends PositionComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class AnimatedComponent extends SpriteAnimationComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ abstract class MyCollidable extends PositionComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down Expand Up @@ -229,7 +229,7 @@ class SnowmanPart extends CircleHitbox {
}

@override
void onCollisionStart(Set<Vector2> intersectionPoints, ShapeHitbox other) {
void onCollisionStart(List<Vector2> intersectionPoints, ShapeHitbox other) {
super.onCollisionStart(intersectionPoints, other);

if (other.hitboxParent is ScreenHitbox) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CollidableEmber extends Ember with CollisionCallbacks {

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class Player extends SpriteComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
final myCenter = Vector2(
Expand Down Expand Up @@ -295,7 +295,7 @@ class Bullet extends PositionComponent with CollisionCallbacks, HasPaint {

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
if (other is Brick) {
Expand Down
2 changes: 1 addition & 1 deletion examples/lib/stories/components/time_scale_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class _Chopper extends SpriteAnimationComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
if (other is _Chopper) {
Expand Down
2 changes: 1 addition & 1 deletion examples/lib/stories/input/joystick_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class JoystickPlayer extends SpriteComponent

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
2 changes: 1 addition & 1 deletion examples/lib/stories/system/step_engine_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class _DetectorComponents extends CircleComponent with CollisionCallbacks {

@override
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
paint.color = BasicPalette.black.color;
Expand Down
10 changes: 5 additions & 5 deletions packages/flame/lib/src/collisions/collision_callbacks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ mixin GenericCollisionCallbacks<T> {
/// [onCollision] is called in every tick when this object is colliding with
/// [other].
@mustCallSuper
void onCollision(Set<Vector2> intersectionPoints, T other) {
void onCollision(List<Vector2> intersectionPoints, T other) {
onCollisionCallback?.call(intersectionPoints, other);
}

/// [onCollisionStart] is called in the first tick when this object starts
/// colliding with [other].
@mustCallSuper
void onCollisionStart(Set<Vector2> intersectionPoints, T other) {
void onCollisionStart(List<Vector2> intersectionPoints, T other) {
activeCollisions.add(other);
onCollisionStartCallback?.call(intersectionPoints, other);
}
Expand Down Expand Up @@ -115,14 +115,14 @@ mixin CollisionCallbacks on Component

@override
@mustCallSuper
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
void onCollision(List<Vector2> intersectionPoints, PositionComponent other) {
onCollisionCallback?.call(intersectionPoints, other);
}

@override
@mustCallSuper
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
activeCollisions.add(other);
Expand Down Expand Up @@ -167,7 +167,7 @@ mixin CollisionCallbacks on Component
/// `onCollisionStartCallback`.
typedef CollisionCallback<T> =
void Function(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
T other,
);

Expand Down
6 changes: 3 additions & 3 deletions packages/flame/lib/src/collisions/collision_detection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ abstract class CollisionDetection<

/// Check what the intersection points of two items are,
/// returns an empty list if there are no intersections.
Set<Vector2> intersections(T itemA, T itemB);
List<Vector2> intersections(T itemA, T itemB);

void handleCollisionStart(Set<Vector2> intersectionPoints, T itemA, T itemB);
void handleCollisionStart(List<Vector2> intersectionPoints, T itemA, T itemB);

void handleCollision(Set<Vector2> intersectionPoints, T itemA, T itemB);
void handleCollision(List<Vector2> intersectionPoints, T itemA, T itemB);

void handleCollisionEnd(T itemA, T itemB);

Expand Down
4 changes: 2 additions & 2 deletions packages/flame/lib/src/collisions/collision_passthrough.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ mixin CollisionPassthrough on CollisionCallbacks {

@override
@mustCallSuper
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
void onCollision(List<Vector2> intersectionPoints, PositionComponent other) {
super.onCollision(intersectionPoints, other);
passthroughParent?.onCollision(intersectionPoints, other);
}

@override
@mustCallSuper
void onCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
Expand Down
2 changes: 1 addition & 1 deletion packages/flame/lib/src/collisions/hitboxes/hitbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class Hitbox<T extends Hitbox<T>>
bool containsPoint(Vector2 point);

/// Where this [Hitbox] has intersection points with another [Hitbox].
Set<Vector2> intersections(T other);
List<Vector2> intersections(T other);

/// This should be a cheaper calculation than comparing the exact boundaries
/// if the exact calculation is expensive.
Expand Down
6 changes: 3 additions & 3 deletions packages/flame/lib/src/collisions/hitboxes/shape_hitbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ mixin ShapeHitbox on ShapeComponent implements Hitbox<ShapeHitbox> {

/// Where this [ShapeComponent] has intersection points with another shape
@override
Set<Vector2> intersections(Hitbox other) {
List<Vector2> intersections(Hitbox other) {
assert(
other is ShapeComponent,
'The intersection can only be performed between shapes',
Expand Down Expand Up @@ -218,7 +218,7 @@ mixin ShapeHitbox on ShapeComponent implements Hitbox<ShapeHitbox> {

@override
@mustCallSuper
void onCollision(Set<Vector2> intersectionPoints, ShapeHitbox other) {
void onCollision(List<Vector2> intersectionPoints, ShapeHitbox other) {
onCollisionCallback?.call(intersectionPoints, other);
if (hitboxParent is CollisionCallbacks &&
triggersParentCollision &&
Expand All @@ -232,7 +232,7 @@ mixin ShapeHitbox on ShapeComponent implements Hitbox<ShapeHitbox> {

@override
@mustCallSuper
void onCollisionStart(Set<Vector2> intersectionPoints, ShapeHitbox other) {
void onCollisionStart(List<Vector2> intersectionPoints, ShapeHitbox other) {
activeCollisions.add(other);
onCollisionStartCallback?.call(intersectionPoints, other);
if (hitboxParent is CollisionCallbacks &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StandardCollisionDetection<B extends Broadphase<ShapeHitbox>>
/// Check what the intersection points of two collidables are,
/// returns an empty list if there are no intersections.
@override
Set<Vector2> intersections(
List<Vector2> intersections(
ShapeHitbox hitboxA,
ShapeHitbox hitboxB,
) {
Expand All @@ -31,7 +31,7 @@ class StandardCollisionDetection<B extends Broadphase<ShapeHitbox>>
/// [ShapeHitbox.hitboxParent] that they have collided with.
@override
void handleCollisionStart(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
ShapeHitbox hitboxA,
ShapeHitbox hitboxB,
) {
Expand All @@ -45,7 +45,7 @@ class StandardCollisionDetection<B extends Broadphase<ShapeHitbox>>
/// [ShapeHitbox.hitboxParent] that they have collided with.
@override
void handleCollision(
Set<Vector2> intersectionPoints,
List<Vector2> intersectionPoints,
ShapeHitbox hitboxA,
ShapeHitbox hitboxB,
) {
Expand Down
Loading
Loading