mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 12:28:03 +08:00
resolve conflit changelog
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
## [next]
|
||||
- Add Joystick Component
|
||||
- Adding BaseGame#markToRemove
|
||||
- Upgrade tiled and flutter_svg dependencies
|
||||
|
||||
## 0.22.1
|
||||
|
||||
@ -45,6 +45,8 @@ A very simple `BaseGame` implementation example can be seen below:
|
||||
}
|
||||
```
|
||||
|
||||
To remove components from the list on a `BaseGame` the `markToRemove` method can be used.
|
||||
|
||||
## Flutter Widgets and Game instances
|
||||
|
||||
Since a Flame game is a widget itself, it is quite easy to use Flutter widgets and Flame game together. But to make it even easier, Flame provides a `mixin` called `HasWidgetsOverlay` which will enable any Flutter widget to be show on top of your game instance, this makes it very easy to create things like a pause menu, or an inventory screen for example.
|
||||
|
||||
2
example/.gitignore
vendored
2
example/.gitignore
vendored
@ -74,3 +74,5 @@ build/
|
||||
|
||||
macos
|
||||
test
|
||||
web
|
||||
lib/generated_plugin_registrant.dart
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
//
|
||||
// Generated file. Do not edit.
|
||||
//
|
||||
|
||||
// ignore: unused_import
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:audioplayers/audioplayers_web.dart';
|
||||
|
||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||
|
||||
void registerPlugins(PluginRegistry registry) {
|
||||
AudioplayersPlugin.registerWith(registry.registrarFor(AudioplayersPlugin));
|
||||
registry.registerMessageHandler();
|
||||
}
|
||||
@ -24,12 +24,6 @@ class Palette {
|
||||
class Square extends PositionComponent with HasGameRef<MyGame> {
|
||||
static const SPEED = 0.25;
|
||||
|
||||
@override
|
||||
void resize(Size size) {
|
||||
x = size.width / 2;
|
||||
y = size.height / 2;
|
||||
}
|
||||
|
||||
@override
|
||||
void render(Canvas c) {
|
||||
prepareCanvas(c);
|
||||
@ -53,16 +47,41 @@ class Square extends PositionComponent with HasGameRef<MyGame> {
|
||||
}
|
||||
}
|
||||
|
||||
class MyGame extends BaseGame with TapDetector {
|
||||
class MyGame extends BaseGame with DoubleTapDetector, TapDetector {
|
||||
final double squareSize = 128;
|
||||
bool running = true;
|
||||
|
||||
MyGame() {
|
||||
add(Square());
|
||||
add(Square()
|
||||
..x = 100
|
||||
..y = 100);
|
||||
}
|
||||
|
||||
@override
|
||||
void onTap() {
|
||||
void onTapUp(details) {
|
||||
final touchArea = Rect.fromCenter(
|
||||
center: details.localPosition,
|
||||
width: 20,
|
||||
height: 20,
|
||||
);
|
||||
|
||||
bool handled = false;
|
||||
components.forEach((c) {
|
||||
if (c is PositionComponent && c.toRect().overlaps(touchArea)) {
|
||||
handled = true;
|
||||
markToRemove(c);
|
||||
}
|
||||
});
|
||||
|
||||
if (!handled) {
|
||||
addLater(Square()
|
||||
..x = touchArea.left
|
||||
..y = touchArea.top);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onDoubleTap() {
|
||||
if (running) {
|
||||
pauseEngine();
|
||||
} else {
|
||||
|
||||
@ -41,6 +41,8 @@ mixin ComposedComponent on Component, HasGameRef, Tapable {
|
||||
OrderedSet<Component> components =
|
||||
OrderedSet(Comparing.on((c) => c.priority()));
|
||||
|
||||
final List<Component> _removeLater = [];
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
canvas.save();
|
||||
@ -59,6 +61,9 @@ mixin ComposedComponent on Component, HasGameRef, Tapable {
|
||||
|
||||
@override
|
||||
void update(double t) {
|
||||
_removeLater.forEach((c) => components.remove(c));
|
||||
_removeLater.clear();
|
||||
|
||||
components.forEach((c) => c.update(t));
|
||||
components.removeWhere((c) => c.destroy());
|
||||
}
|
||||
@ -70,6 +75,10 @@ mixin ComposedComponent on Component, HasGameRef, Tapable {
|
||||
components.add(c);
|
||||
}
|
||||
|
||||
void markToRemove(Component component) {
|
||||
_removeLater.add(component);
|
||||
}
|
||||
|
||||
// this is an important override for the Tapable mixin
|
||||
@override
|
||||
Iterable<Tapable> tapableChildren() => _findT<Tapable>();
|
||||
|
||||
@ -27,6 +27,9 @@ class BaseGame extends Game {
|
||||
/// Components added by the [addLater] method
|
||||
final List<Component> _addLater = [];
|
||||
|
||||
/// Components to be removed on the next update
|
||||
final List<Component> _removeLater = [];
|
||||
|
||||
/// Current screen size, updated every resize via the [resize] method hook
|
||||
Size size;
|
||||
|
||||
@ -86,6 +89,11 @@ class BaseGame extends Game {
|
||||
_addLater.add(c);
|
||||
}
|
||||
|
||||
/// Marks a component to be removed from the components list on the next game loop cycle
|
||||
void markToRemove(Component c) {
|
||||
_removeLater.add(c);
|
||||
}
|
||||
|
||||
/// This implementation of render basically calls [renderComponent] for every component, making sure the canvas is reset for each one.
|
||||
///
|
||||
/// You can override it further to add more custom behaviour.
|
||||
@ -119,6 +127,9 @@ class BaseGame extends Game {
|
||||
/// You can override it further to add more custom behaviour.
|
||||
@override
|
||||
void update(double t) {
|
||||
_removeLater.forEach((c) => components.remove(c));
|
||||
_removeLater.clear();
|
||||
|
||||
components.addAll(_addLater);
|
||||
_addLater.clear();
|
||||
|
||||
|
||||
@ -7,50 +7,23 @@ if [[ $(flutter format -n .) ]]; then
|
||||
fi
|
||||
|
||||
flutter pub get
|
||||
result=$(dartanalyzer lib/)
|
||||
|
||||
# We need to run pubget on all the examples
|
||||
for f in doc/examples/**/pubspec.yaml; do
|
||||
d=$(dirname $f)
|
||||
cd $d
|
||||
flutter pub get
|
||||
cd - > /dev/null
|
||||
done
|
||||
|
||||
cd .
|
||||
flutter pub get
|
||||
result=$(flutter analyze .)
|
||||
if ! echo "$result" | grep -q "No issues found!"; then
|
||||
echo "$result"
|
||||
echo "dartanalyzer issue: lib"
|
||||
echo "flutter analyze issue: $1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
analyzer() {
|
||||
cd $1
|
||||
flutter pub get
|
||||
result=$(dartanalyzer .)
|
||||
if ! echo "$result" | grep -q "No issues found!"; then
|
||||
echo "$result"
|
||||
echo "dartanalyzer issue: $1"
|
||||
exit 1
|
||||
fi
|
||||
cd - > /dev/null
|
||||
}
|
||||
|
||||
analyzer "example"
|
||||
|
||||
# Examples that are changed
|
||||
changed=$(git diff --name-only origin/develop doc/examples \
|
||||
| xargs -I {} dirname {} | sed 's/\/lib$//' | uniq \
|
||||
| xargs -I {} find {} -name pubspec.yaml | xargs -I {} dirname {})
|
||||
|
||||
# Examples that are affected by changed code
|
||||
affected=$(git diff --name-only origin/develop lib/ \
|
||||
| xargs -I {} basename {} | xargs -I {} grep -r -l --include \*.dart {} doc/examples/ \
|
||||
| xargs -I {} dirname {} | sed 's/\/lib$//' | uniq \
|
||||
| xargs -I {} find {} -name pubspec.yaml | xargs -I {} dirname {})
|
||||
|
||||
both=("${changed[@]}" "${affected[@]}")
|
||||
lint_examples=$(printf "%s\n" "${both[@]}" | sort -u)
|
||||
for d in $lint_examples; do
|
||||
analyzer $d
|
||||
done
|
||||
|
||||
for f in doc/examples/**/pubspec.yaml; do
|
||||
d=$(dirname $f)
|
||||
if [[ ! " ${lint_examples[@]} " =~ " ${d} " ]]; then
|
||||
analyzer $d
|
||||
fi
|
||||
done
|
||||
|
||||
echo "success"
|
||||
exit 0
|
||||
|
||||
@ -14,9 +14,6 @@ class MyGame extends BaseGame {
|
||||
}
|
||||
|
||||
class MyComponent extends PositionComponent with HasGameRef<MyGame> {
|
||||
@override
|
||||
void update(double dt) {}
|
||||
|
||||
@override
|
||||
void render(Canvas c) {}
|
||||
|
||||
|
||||
@ -15,9 +15,6 @@ class MyComponent extends PositionComponent with Resizable {
|
||||
@override
|
||||
Iterable<Resizable> resizableChildren() => myChildren;
|
||||
|
||||
@override
|
||||
void update(double dt) {}
|
||||
|
||||
@override
|
||||
void render(Canvas c) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user