mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
Rename Tapeable to Tapable
This commit is contained in:
committed by
Erick (CptBlackPixel)
parent
f18e6bbea1
commit
a349754428
@ -1,3 +1,3 @@
|
||||
# tapeables
|
||||
# tapables
|
||||
|
||||
A Flame game showcasing how to use a tapeable component
|
||||
A Flame game showcasing how to use a tapable component
|
||||
|
||||
@ -1,20 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/components/component.dart';
|
||||
import 'package:flame/components/mixins/tapeable.dart';
|
||||
import 'package:flame/components/mixins/tapable.dart';
|
||||
|
||||
void main() {
|
||||
final game = MyGame();
|
||||
runApp(game.widget);
|
||||
}
|
||||
|
||||
class TapeableSquare extends PositionComponent with Tapeable {
|
||||
class TapableSquare extends PositionComponent with Tapable {
|
||||
static final Paint _white = Paint()..color = const Color(0xFFFFFFFF);
|
||||
static final Paint _grey = Paint()..color = const Color(0xFFA5A5A5);
|
||||
|
||||
bool _beenPressed = false;
|
||||
|
||||
TapeableSquare({double y = 100}) {
|
||||
TapableSquare({double y = 100}) {
|
||||
x = width = height = 100;
|
||||
this.y = y;
|
||||
}
|
||||
@ -45,7 +45,7 @@ class TapeableSquare extends PositionComponent with Tapeable {
|
||||
|
||||
class MyGame extends BaseGame {
|
||||
MyGame() {
|
||||
add(TapeableSquare());
|
||||
add(TapeableSquare(y: 400));
|
||||
add(TapableSquare());
|
||||
add(TapableSquare(y: 400));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name: tapeables
|
||||
description: A flame game showcasing the use of tapeable components
|
||||
name: tapables
|
||||
description: A flame game showcasing the use of tapable components
|
||||
|
||||
version: 1.0.0+1
|
||||
|
||||
|
||||
@ -37,9 +37,9 @@ Here are some example of more complex Gesture Recognizers:
|
||||
```
|
||||
__ATTENTION:__ `Flame.util.addGestureRecognizer` must be called after the `runApp`, otherwise Flutter's `GestureBinding` will not be initialized yet and exceptions will occur.
|
||||
|
||||
## Tapeable components
|
||||
## Tapable components
|
||||
|
||||
Flame also offers a simple helper to make it easier to handle tap events on `PositionComponent`, by using the mixin `Tapeable` your components can override the following methods, enabling easy to use tap events on your Component.
|
||||
Flame also offers a simple helper to make it easier to handle tap events on `PositionComponent`, by using the mixin `Tapable` your components can override the following methods, enabling easy to use tap events on your Component.
|
||||
|
||||
```dart
|
||||
void onTapCancel() {}
|
||||
@ -53,7 +53,7 @@ Minimal component example:
|
||||
import 'package:flame/components/component.dart';
|
||||
import 'package:flame/components/events/gestures.dart';
|
||||
|
||||
class TapeableComponent extends PositionComponent with Tapeable {
|
||||
class TapableComponent extends PositionComponent with Tapable {
|
||||
|
||||
// update and render omitted
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flame/components/mixins/has_game_ref.dart';
|
||||
import 'package:flame/components/mixins/tapeable.dart';
|
||||
import 'package:flame/components/mixins/tapable.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:ordered_set/comparing.dart';
|
||||
import 'package:ordered_set/ordered_set.dart';
|
||||
@ -37,7 +37,7 @@ import 'mixins/resizable.dart';
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
mixin ComposedComponent on Component, HasGameRef, Tapeable {
|
||||
mixin ComposedComponent on Component, HasGameRef, Tapable {
|
||||
OrderedSet<Component> components =
|
||||
OrderedSet(Comparing.on((c) => c.priority()));
|
||||
|
||||
@ -67,9 +67,9 @@ mixin ComposedComponent on Component, HasGameRef, Tapeable {
|
||||
components.add(c);
|
||||
}
|
||||
|
||||
// this is an important override for the Tapeable mixin
|
||||
// this is an important override for the Tapable mixin
|
||||
@override
|
||||
Iterable<Tapeable> tapeableChildren() => _findT<Tapeable>();
|
||||
Iterable<Tapable> tapableChildren() => _findT<Tapable>();
|
||||
|
||||
// this is an important override for the Resizable mixin
|
||||
Iterable<Resizable> resizableChildren() => _findT<Resizable>();
|
||||
|
||||
@ -2,7 +2,7 @@ import 'dart:ui';
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
|
||||
mixin Tapeable {
|
||||
mixin Tapable {
|
||||
Rect toRect();
|
||||
|
||||
void onTapCancel() {}
|
||||
@ -15,23 +15,23 @@ mixin Tapeable {
|
||||
if (checkTapOverlap(details.globalPosition)) {
|
||||
onTapDown(details);
|
||||
}
|
||||
tapeableChildren().forEach((c) => c.handleTapDown(details));
|
||||
tapableChildren().forEach((c) => c.handleTapDown(details));
|
||||
}
|
||||
|
||||
void handleTapUp(TapUpDetails details) {
|
||||
if (checkTapOverlap(details.globalPosition)) {
|
||||
onTapUp(details);
|
||||
}
|
||||
tapeableChildren().forEach((c) => c.handleTapUp(details));
|
||||
tapableChildren().forEach((c) => c.handleTapUp(details));
|
||||
}
|
||||
|
||||
void handleTapCancel() {
|
||||
onTapCancel();
|
||||
tapeableChildren().forEach((c) => c.handleTapCancel());
|
||||
tapableChildren().forEach((c) => c.handleTapCancel());
|
||||
}
|
||||
|
||||
/// Overwrite this to add children to this [Tapeable].
|
||||
/// Overwrite this to add children to this [Tapable].
|
||||
///
|
||||
/// If a [Tapeable] has children, its children be taped as well.
|
||||
Iterable<Tapeable> tapeableChildren() => [];
|
||||
/// If a [Tapable] has children, its children be taped as well.
|
||||
Iterable<Tapable> tapableChildren() => [];
|
||||
}
|
||||
@ -11,7 +11,7 @@ import 'package:ordered_set/ordered_set.dart';
|
||||
|
||||
import 'components/component.dart';
|
||||
import 'components/mixins/has_game_ref.dart';
|
||||
import 'components/mixins/tapeable.dart';
|
||||
import 'components/mixins/tapable.dart';
|
||||
import 'flame.dart';
|
||||
import 'position.dart';
|
||||
|
||||
@ -111,22 +111,22 @@ abstract class BaseGame extends Game {
|
||||
/// List of deltas used in debug mode to calculate FPS
|
||||
final List<double> _dts = [];
|
||||
|
||||
Iterable<Tapeable> get _tapeableComponents =>
|
||||
components.where((c) => c is Tapeable).cast();
|
||||
Iterable<Tapable> get _tapableComponents =>
|
||||
components.where((c) => c is Tapable).cast();
|
||||
|
||||
@override
|
||||
void onTapCancel() {
|
||||
_tapeableComponents.forEach((c) => c.handleTapCancel());
|
||||
_tapableComponents.forEach((c) => c.handleTapCancel());
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapDown(TapDownDetails details) {
|
||||
_tapeableComponents.forEach((c) => c.handleTapDown(details));
|
||||
_tapableComponents.forEach((c) => c.handleTapDown(details));
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapUp(TapUpDetails details) {
|
||||
_tapeableComponents.forEach((c) => c.handleTapUp(details));
|
||||
_tapableComponents.forEach((c) => c.handleTapUp(details));
|
||||
}
|
||||
|
||||
/// This method is called for every component added, both via [add] and [addLater] methods.
|
||||
|
||||
@ -3,7 +3,7 @@ import 'dart:ui';
|
||||
import 'package:flame/components/composed_component.dart';
|
||||
import 'package:flame/components/mixins/has_game_ref.dart';
|
||||
import 'package:flame/components/mixins/resizable.dart';
|
||||
import 'package:flame/components/mixins/tapeable.dart';
|
||||
import 'package:flame/components/mixins/tapable.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
@ -12,7 +12,7 @@ import 'package:flame/components/component.dart';
|
||||
|
||||
class MyGame extends BaseGame {}
|
||||
|
||||
class MyTap extends PositionComponent with Tapeable, Resizable {
|
||||
class MyTap extends PositionComponent with Tapable, Resizable {
|
||||
bool tapped = false;
|
||||
|
||||
@override
|
||||
@ -31,7 +31,7 @@ class MyTap extends PositionComponent with Tapeable, Resizable {
|
||||
}
|
||||
|
||||
class MyComposed extends Component
|
||||
with HasGameRef, Tapeable, ComposedComponent {
|
||||
with HasGameRef, Tapable, ComposedComponent {
|
||||
@override
|
||||
void update(double dt) {}
|
||||
|
||||
@ -42,7 +42,7 @@ class MyComposed extends Component
|
||||
Rect toRect() => Rect.zero;
|
||||
}
|
||||
|
||||
class PositionComponentNoNeedForRect extends PositionComponent with Tapeable {
|
||||
class PositionComponentNoNeedForRect extends PositionComponent with Tapable {
|
||||
@override
|
||||
void render(Canvas c) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user