mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 04:18:25 +08:00
Added priority rendering/updating to BaseGame
This commit is contained in:
@ -42,6 +42,14 @@ abstract class Component {
|
|||||||
///
|
///
|
||||||
/// HUD objects ignore the [BaseGame.camera] when rendered (so their position coordinates are considered relative to the device screen).
|
/// HUD objects ignore the [BaseGame.camera] when rendered (so their position coordinates are considered relative to the device screen).
|
||||||
bool isHud() => false;
|
bool isHud() => false;
|
||||||
|
|
||||||
|
/// Render priority of this component. This allows you to control the order in which your components are rendered.
|
||||||
|
///
|
||||||
|
/// Components are always updated and rendered in the order defined by this number.
|
||||||
|
/// The smaller the priority, the sooner your component will be updated/rendered.
|
||||||
|
/// It can be any integer (negative, zero, or positive).
|
||||||
|
/// If two components share the same priority, they will probably be drawn in the order they were added.
|
||||||
|
int priority() => 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [Component] implementation that represents a component that has a specific, possibly mutatable position on the screen.
|
/// A [Component] implementation that represents a component that has a specific, possibly mutatable position on the screen.
|
||||||
|
|||||||
@ -6,6 +6,9 @@ import 'package:flutter/rendering.dart';
|
|||||||
import 'package:flutter/scheduler.dart';
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
|
import 'package:ordered_set/ordered_set.dart';
|
||||||
|
import 'package:ordered_set/comparing.dart';
|
||||||
|
|
||||||
import 'components/component.dart';
|
import 'components/component.dart';
|
||||||
import 'position.dart';
|
import 'position.dart';
|
||||||
|
|
||||||
@ -151,7 +154,7 @@ class _GameRenderBox extends RenderBox with WidgetsBindingObserver {
|
|||||||
/// It is based on the Component system.
|
/// It is based on the Component system.
|
||||||
abstract class BaseGame extends Game {
|
abstract class BaseGame extends Game {
|
||||||
/// The list of components to be updated and rendered by the base game.
|
/// The list of components to be updated and rendered by the base game.
|
||||||
List<Component> components = [];
|
OrderedSet<Component> components = new OrderedSet(Comparing.on((c) => c.priority()));
|
||||||
|
|
||||||
/// Components added by the [addLater] method
|
/// Components added by the [addLater] method
|
||||||
List<Component> _addLater = [];
|
List<Component> _addLater = [];
|
||||||
|
|||||||
@ -10,7 +10,8 @@ flutter:
|
|||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
audioplayers: 0.5.2
|
audioplayers: ^0.5.2
|
||||||
|
ordered_set: ^1.1.0
|
||||||
path_provider: ^0.4.0
|
path_provider: ^0.4.0
|
||||||
box2d: ^0.4.0
|
box2d: ^0.4.0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user