mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 13:08:09 +08:00 
			
		
		
		
	* Animations, CameraAndViewport, CollisionDetection and Components unified * Added descriptions to effects * Rename input games * Unify input stories * Add info to parallax section * Added descriptions to the rendering examples * Add descriptions to the sprites directory * Fix utils and rendering section * Add descriptions to the widgets section * Delete directory that rebase brought back * Unify game names * Added some styleguide docs for examples * Fix analyze issues * All files should have _example as suffix * Made the FollowComponentExample a bit easier to understand * Change priority of ember
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
import 'package:flame/components.dart';
 | 
						|
import 'package:flame/game.dart';
 | 
						|
 | 
						|
import '../input/draggables_example.dart';
 | 
						|
import 'composability_example.dart';
 | 
						|
 | 
						|
class GameInGameExample extends FlameGame with HasDraggables {
 | 
						|
  static const String description = '''
 | 
						|
    This example shows two games having another game as a parent.
 | 
						|
    One game contains draggable components and the other is a rotating square
 | 
						|
    with other square children.
 | 
						|
    After 5 seconds, one of the components from the game with draggable squares
 | 
						|
    changes its parent from its original game to the component that is rotating.
 | 
						|
    After another 5 seconds it changes back to its original parent, and so on.
 | 
						|
  ''';
 | 
						|
 | 
						|
  @override
 | 
						|
  bool debugMode = true;
 | 
						|
  late final ComposabilityExample composedGame;
 | 
						|
  late final DraggablesExample draggablesGame;
 | 
						|
 | 
						|
  @override
 | 
						|
  Future<void> onLoad() async {
 | 
						|
    await super.onLoad();
 | 
						|
    composedGame = ComposabilityExample();
 | 
						|
    draggablesGame = DraggablesExample(zoom: 1.0);
 | 
						|
 | 
						|
    await add(composedGame);
 | 
						|
    await add(draggablesGame);
 | 
						|
 | 
						|
    add(GameChangeTimer());
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
class GameChangeTimer extends TimerComponent
 | 
						|
    with HasGameRef<GameInGameExample> {
 | 
						|
  GameChangeTimer() : super(period: 5, repeat: true);
 | 
						|
 | 
						|
  @override
 | 
						|
  void onTick() {
 | 
						|
    final child = gameRef.draggablesGame.square;
 | 
						|
    final newParent = child.parent == gameRef.draggablesGame
 | 
						|
        ? gameRef.composedGame.parentSquare
 | 
						|
        : gameRef.draggablesGame;
 | 
						|
    child.changeParent(newParent);
 | 
						|
  }
 | 
						|
}
 |