mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	 6b2f8032fe
			
		
	
	6b2f8032fe
	
	
	
		
			
			* some initial refactoring * Fixing examples and joystick component * Fixing examples * Addressing comments from PR * Fixing tutorials * Updating docs * Fixing tests * PR followup * A big follow up * linting * doc nit * Changelog and fix tutorial * Addressing comments * Fixing BaseGame project and scale offset methods * Formatting * doc suggestions * Update packages/flame/lib/src/gestures/events.dart Co-authored-by: Luan Nico <luanpotter27@gmail.com> * Hopefully, the last follow up * Linting and adding dart-code-metrics again * fixing tutorial Co-authored-by: Luan Nico <luanpotter27@gmail.com>
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:flutter/material.dart';
 | |
| import 'package:flame/game.dart';
 | |
| import 'package:flame/gestures.dart';
 | |
| import 'package:flame/palette.dart';
 | |
| import 'package:flame/extensions.dart';
 | |
| 
 | |
| class ScrollGame extends BaseGame with ScrollDetector {
 | |
|   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 event) {
 | |
|     target = position + event.scrollDelta * 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);
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| }
 |