mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 08:56:01 +08:00 
			
		
		
		
	 637c258b25
			
		
	
	637c258b25
	
	
	
		
			
			This change makes it possible to have the collision detection system further down in the tree than on the FlameGame, this enables you to have collision detection on the World component for example.
Today it doesn't work if you have several worlds where the components are overlapping across the worlds, since the hitboxes live on top level.
So now you can use a World like this:
class CollisionDetectionWorld extends World with HasCollisionDetection {}
and all hitboxes added in there will only react with other hitboxes added to that world.
		
	
		
			
				
	
	
		
			80 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:dashbook/dashbook.dart';
 | |
| import 'package:examples/commons/commons.dart';
 | |
| import 'package:examples/stories/collision_detection/bouncing_ball_example.dart';
 | |
| import 'package:examples/stories/collision_detection/circles_example.dart';
 | |
| import 'package:examples/stories/collision_detection/collidable_animation_example.dart';
 | |
| import 'package:examples/stories/collision_detection/multiple_shapes_example.dart';
 | |
| import 'package:examples/stories/collision_detection/multiple_worlds_example.dart';
 | |
| import 'package:examples/stories/collision_detection/quadtree_example.dart';
 | |
| import 'package:examples/stories/collision_detection/raycast_example.dart';
 | |
| import 'package:examples/stories/collision_detection/raycast_light_example.dart';
 | |
| import 'package:examples/stories/collision_detection/raycast_max_distance_example.dart';
 | |
| import 'package:examples/stories/collision_detection/raytrace_example.dart';
 | |
| import 'package:flame/game.dart';
 | |
| 
 | |
| void addCollisionDetectionStories(Dashbook dashbook) {
 | |
|   dashbook.storiesOf('Collision Detection')
 | |
|     ..add(
 | |
|       'Collidable AnimationComponent',
 | |
|       (_) => GameWidget(game: CollidableAnimationExample()),
 | |
|       codeLink:
 | |
|           baseLink('collision_detection/collidable_animation_example.dart'),
 | |
|       info: CollidableAnimationExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Circles',
 | |
|       (_) => GameWidget(game: CirclesExample()),
 | |
|       codeLink: baseLink('collision_detection/circles_example.dart'),
 | |
|       info: CirclesExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Bouncing Ball',
 | |
|       (_) => GameWidget(game: BouncingBallExample()),
 | |
|       codeLink: baseLink('collision_detection/bouncing_ball_example.dart'),
 | |
|       info: BouncingBallExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Multiple shapes',
 | |
|       (_) => GameWidget(game: MultipleShapesExample()),
 | |
|       codeLink: baseLink('collision_detection/multiple_shapes_example.dart'),
 | |
|       info: MultipleShapesExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Multiple worlds',
 | |
|       (_) => GameWidget(game: MultipleWorldsExample()),
 | |
|       codeLink: baseLink('collision_detection/multiple_worlds_example.dart'),
 | |
|       info: MultipleWorldsExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'QuadTree collision',
 | |
|       (_) => GameWidget(game: QuadTreeExample()),
 | |
|       codeLink: baseLink('collision_detection/quadtree_example.dart'),
 | |
|       info: QuadTreeExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Raycasting (light)',
 | |
|       (_) => GameWidget(game: RaycastLightExample()),
 | |
|       codeLink: baseLink('collision_detection/raycast_light_example.dart'),
 | |
|       info: RaycastLightExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Raycasting',
 | |
|       (_) => GameWidget(game: RaycastExample()),
 | |
|       codeLink: baseLink('collision_detection/raycast_example.dart'),
 | |
|       info: RaycastExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Raytracing',
 | |
|       (_) => GameWidget(game: RaytraceExample()),
 | |
|       codeLink: baseLink('collision_detection/raytrace_example.dart'),
 | |
|       info: RaytraceExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Raycasting Max Distance',
 | |
|       (_) => GameWidget(game: RaycastMaxDistanceExample()),
 | |
|       codeLink:
 | |
|           baseLink('collision_detection/raycast_max_distance_example.dart'),
 | |
|       info: RaycastMaxDistanceExample.description,
 | |
|     );
 | |
| }
 |