mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
36 lines
967 B
Dart
36 lines
967 B
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/palette.dart';
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
import 'package:flame_forge2d/forge2d_game.dart';
|
|
import 'package:forge2d/forge2d.dart';
|
|
|
|
import 'balls.dart';
|
|
import 'boundaries.dart';
|
|
|
|
class TappableSample extends Forge2DGame with HasTappables {
|
|
TappableSample() : super(zoom: 20, gravity: Vector2(0, -10.0));
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
await super.onLoad();
|
|
final boundaries = createBoundaries(this);
|
|
boundaries.forEach(add);
|
|
final center = screenToWorld(camera.viewport.effectiveSize / 2);
|
|
add(TappableBall(center));
|
|
}
|
|
}
|
|
|
|
class TappableBall extends Ball with Tappable {
|
|
TappableBall(Vector2 position) : super(position) {
|
|
originalPaint = BasicPalette.white.paint();
|
|
paint = originalPaint;
|
|
}
|
|
|
|
@override
|
|
bool onTapDown(_) {
|
|
body.applyLinearImpulse(Vector2.random() * 1000);
|
|
paint = randomPaint();
|
|
return false;
|
|
}
|
|
}
|