mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 13:08:09 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
import 'package:flame/sprite_animation.dart';
 | 
						|
import 'package:flame/components/sprite_animation_component.dart';
 | 
						|
import 'package:flame/flame.dart';
 | 
						|
import 'package:flame/game.dart';
 | 
						|
import 'package:flame/extensions/vector2.dart';
 | 
						|
import 'package:flutter/material.dart';
 | 
						|
 | 
						|
void main() async {
 | 
						|
  WidgetsFlutterBinding.ensureInitialized();
 | 
						|
  final Vector2 size = await Flame.util.initialDimensions();
 | 
						|
  final game = MyGame(size);
 | 
						|
  runApp(game.widget);
 | 
						|
}
 | 
						|
 | 
						|
class MyGame extends BaseGame {
 | 
						|
  final animation = SpriteAnimation.sequenced(
 | 
						|
    'chopper.png',
 | 
						|
    4,
 | 
						|
    textureSize: Vector2.all(48),
 | 
						|
    stepTime: 0.15,
 | 
						|
  );
 | 
						|
 | 
						|
  SpriteAnimationComponent buildAnimation() {
 | 
						|
    final ac = SpriteAnimationComponent(Vector2.all(100), animation);
 | 
						|
    ac.x = size.x / 2 - ac.width / 2;
 | 
						|
    return ac;
 | 
						|
  }
 | 
						|
 | 
						|
  MyGame(Vector2 screenSize) {
 | 
						|
    size = screenSize;
 | 
						|
 | 
						|
    final regular = buildAnimation();
 | 
						|
    regular.y = 100;
 | 
						|
    add(regular);
 | 
						|
 | 
						|
    final flipX = buildAnimation();
 | 
						|
    flipX.y = 300;
 | 
						|
    flipX.renderFlipX = true;
 | 
						|
    add(flipX);
 | 
						|
 | 
						|
    final flipY = buildAnimation();
 | 
						|
    flipY.y = 500;
 | 
						|
    flipY.renderFlipY = true;
 | 
						|
    add(flipY);
 | 
						|
  }
 | 
						|
}
 |