Files
Erick 6b2f8032fe Making Flame events aware of camera (#755)
* 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>
2021-04-15 15:28:46 -03:00

51 lines
1.1 KiB
Dart

import 'package:flame/components.dart';
import 'package:flutter/material.dart';
import 'package:flame/game.dart';
import 'package:flame/extensions.dart';
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;
TapableSquare({Vector2? position})
: super(
position: position ?? Vector2.all(100),
size: Vector2.all(100),
);
@override
void render(Canvas canvas) {
super.render(canvas);
canvas.drawRect(size.toRect(), _beenPressed ? _grey : _white);
}
@override
bool onTapUp(_) {
_beenPressed = false;
return true;
}
@override
bool onTapDown(_) {
_beenPressed = true;
angle += 1.0;
return true;
}
@override
bool onTapCancel() {
_beenPressed = false;
return true;
}
}
class TapablesGame extends BaseGame with HasTapableComponents {
@override
Future<void> onLoad() async {
add(TapableSquare()..anchor = Anchor.center);
add(TapableSquare()..y = 350);
}
}