mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 17:06:50 +08:00 
			
		
		
		
	 5c47d7f6d7
			
		
	
	5c47d7f6d7
	
	
	
		
			
			* Added Component.childrenFactory * fix some of the lint warnings * more lint warnings * remove changelog entry * more analyzer warnings * one more warning * one more warning * remove more unused imports * fix more warnings * another warning * one more warning * a lot more warnings * some more warnings * fix warnings in flame_svg * fix warnings in flame_bloc * Remove OrderedSet override feature * Remove testRandom change * Remove unnecessary type checks * Re-remove deprecated argument in random_test Co-authored-by: Pasha Stetsenko <stpasha@google.com>
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:flame/extensions.dart';
 | |
| import 'package:flame/game.dart';
 | |
| import 'package:flame/input.dart';
 | |
| import 'package:flame/palette.dart';
 | |
| 
 | |
| class ScrollExample extends FlameGame with ScrollDetector {
 | |
|   static const String description = '''
 | |
|     In this example we show how to use the `ScrollDetector`.\n\n
 | |
|     Scroll within the canvas (both horizontally and vertically) and the white
 | |
|     square will move around.
 | |
|   ''';
 | |
| 
 | |
|   static const speed = 2000.0;
 | |
|   final _size = Vector2.all(50);
 | |
|   final _paint = BasicPalette.white.paint();
 | |
| 
 | |
|   Vector2 position = Vector2.all(100);
 | |
|   Vector2? target;
 | |
| 
 | |
|   @override
 | |
|   void onScroll(PointerScrollInfo info) {
 | |
|     target = position + info.scrollDelta.game * 5;
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void render(Canvas canvas) {
 | |
|     super.render(canvas);
 | |
|     canvas.drawRect(position.toPositionedRect(_size), _paint);
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void update(double dt) {
 | |
|     super.update(dt);
 | |
|     final target = this.target;
 | |
|     final ds = speed * dt;
 | |
|     if (target != null) {
 | |
|       if (position != target) {
 | |
|         final diff = target - position;
 | |
|         if (diff.length < ds) {
 | |
|           position.setFrom(target);
 | |
|         } else {
 | |
|           diff.scaleTo(ds);
 | |
|           position.setFrom(position + diff);
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| }
 |