Skip to content

Commit

Permalink
fix: collision detection order change
Browse files Browse the repository at this point in the history
  • Loading branch information
ASGAlex committed Dec 18, 2023
1 parent bdd339e commit f8b7c58
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
5 changes: 4 additions & 1 deletion example/lib/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,10 @@ class Player extends SpriteComponent
) {
final myCenter = boundingBox.aabbCenter;
if (other is GameCollideable || other is CellLayer) {
if (other is GameCollideable) {
if (game.player == this) {
position.setFrom(positionNoCollision);
game.camera.updateTree(0.01);
} else if (other is GameCollideable) {
final diffX = myCenter.x - other.boundingBox.aabbCenter.x;
if (diffX < 0) {
canMoveRight = false;
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ environment:
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flame: ^1.10.1
flame: ^1.12.0
flame_spatial_grid: #0.8.0
path: ../
flame_message_stream: 0.0.2
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/layers/cell_trail_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ class CellTrailLayer extends CellStaticLayer {

if (fadeOutConfig.isFadeOut) {
_fadeOutDt += dt;
isUpdateNeeded = true;
if (doFadeOut) {
isUpdateNeeded = true;
updateLayer(dt);
}
}
Expand Down
13 changes: 11 additions & 2 deletions lib/src/core/has_spatial_grid_framework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,10 @@ mixin HasSpatialGridFramework<W extends World> on FlameGame<W>
_collectDt(dt);

tickersManager.update(dt);
collisionDetection.dt = dt;
collisionDetection.run();

super.update(dt);
collisionDetection.dt = dt;
collisionDetection.run();
}
} else {
final stopwatch = Stopwatch()..start();
Expand Down Expand Up @@ -934,6 +934,15 @@ mixin HasSpatialGridFramework<W extends World> on FlameGame<W>
this,
);
progressManager.setProgress(100);
const dt = 0.001;
_loadWholeMap();
_buildNewCells();
_runScheduledLayerOperations();
_collectDt(dt);

tickersManager.update(dt);
collisionDetection.dt = dt;
collisionDetection.run();

_gameInitializationFinished = true;
onInitializationDone();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
sdk: '>=3.0.0 <4.0.0'

dependencies:
flame: ^1.10.1
flame: ^1.12.0
flame_tiled: ^1.12.0
meta: ^1.8.0
isolate_manager: ^4.1.3
Expand Down

0 comments on commit f8b7c58

Please sign in to comment.