mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 20:36:31 +08:00
* Refactor joystick * Fix directional tests * Joystick example * Any PositionComponent can be used as knob and background * Add MarginButtonComponent * Fix JoystickExample * Update joystick docs * Fix joystick direction tests * Fix effect tests * Fix analyze issue * Update docs * Update docs * Move joystick to input export * Update packages/flame/lib/src/geometry/shape.dart Co-authored-by: Luan Nico <luanpotter27@gmail.com> * Add test and description for screenAngle * Update examples/lib/stories/controls/joystick_player.dart Co-authored-by: Erick <erickzanardoo@gmail.com> * Update doc/input.md Co-authored-by: Erick <erickzanardoo@gmail.com> * controls -> input in examples to align with export file * controls -> input * Add simple joystick example * Fix imports * velocity -> relativeDelta Co-authored-by: Luan Nico <luanpotter27@gmail.com> Co-authored-by: Erick <erickzanardoo@gmail.com>
59 lines
1.5 KiB
Dart
59 lines
1.5 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'package:flame/components.dart';
|
|
import 'package:flame/input.dart';
|
|
import 'package:flame_forge2d/forge2d_game.dart';
|
|
import 'package:flame_forge2d/sprite_body_component.dart';
|
|
import 'package:forge2d/forge2d.dart';
|
|
|
|
import 'boundaries.dart';
|
|
|
|
class Pizza extends SpriteBodyComponent {
|
|
final Vector2 _position;
|
|
|
|
Pizza(this._position, Image image) : super(Sprite(image), Vector2(10, 15));
|
|
|
|
@override
|
|
Body createBody() {
|
|
final shape = PolygonShape();
|
|
|
|
final vertices = [
|
|
Vector2(-size.x / 2, -size.y / 2),
|
|
Vector2(size.x / 2, -size.y / 2),
|
|
Vector2(0, size.y / 2),
|
|
];
|
|
shape.set(vertices);
|
|
|
|
final fixtureDef = FixtureDef(shape)
|
|
..userData = this // To be able to determine object in collision
|
|
..restitution = 0.3
|
|
..density = 1.0
|
|
..friction = 0.2;
|
|
|
|
final bodyDef = BodyDef()
|
|
..position = _position
|
|
..angle = (_position.x + _position.y) / 2 * 3.14
|
|
..type = BodyType.dynamic;
|
|
return world.createBody(bodyDef)..createFixture(fixtureDef);
|
|
}
|
|
}
|
|
|
|
class SpriteBodySample extends Forge2DGame with TapDetector {
|
|
late Image _pizzaImage;
|
|
|
|
SpriteBodySample() : super(gravity: Vector2(0, -10.0));
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
_pizzaImage = await images.load('pizza.png');
|
|
addAll(createBoundaries(this));
|
|
}
|
|
|
|
@override
|
|
void onTapDown(TapDownInfo details) {
|
|
super.onTapDown(details);
|
|
final position = details.eventPosition.game;
|
|
add(Pizza(position, _pizzaImage));
|
|
}
|
|
}
|