mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			35 lines
		
	
	
		
			943 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			943 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:flame/components.dart';
 | |
| import 'package:flame/palette.dart';
 | |
| import 'package:flame_forge2d/flame_forge2d.dart';
 | |
| import 'package:flame_forge2d/forge2d_game.dart';
 | |
| import 'package:forge2d/forge2d.dart';
 | |
| 
 | |
| import 'balls.dart';
 | |
| import 'boundaries.dart';
 | |
| 
 | |
| class TappableSample extends Forge2DGame with HasTappableComponents {
 | |
|   TappableSample() : super(zoom: 20, gravity: Vector2(0, -10.0));
 | |
| 
 | |
|   @override
 | |
|   Future<void> onLoad() async {
 | |
|     final boundaries = createBoundaries(this);
 | |
|     boundaries.forEach(add);
 | |
|     final center = screenToWorld(viewport.effectiveSize / 2);
 | |
|     add(TappableBall(center));
 | |
|   }
 | |
| }
 | |
| 
 | |
| class TappableBall extends Ball with Tappable {
 | |
|   TappableBall(Vector2 position) : super(position) {
 | |
|     originalPaint = BasicPalette.white.paint();
 | |
|     paint = originalPaint;
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   bool onTapDown(_) {
 | |
|     body.applyLinearImpulse(Vector2.random() * 1000);
 | |
|     paint = randomPaint();
 | |
|     return false;
 | |
|   }
 | |
| }
 | 
