mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-18 21:57:15 +08:00
* Introduce updateTree * Update tests * Fix update for game-in-game situations * Add dartdoc to updateTree
32 lines
699 B
Dart
32 lines
699 B
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
|
|
class JoystickPlayer extends SpriteComponent with HasGameRef {
|
|
/// Pixels/s
|
|
double maxSpeed = 300.0;
|
|
|
|
final JoystickComponent joystick;
|
|
|
|
JoystickPlayer(this.joystick)
|
|
: super(
|
|
size: Vector2.all(100.0),
|
|
) {
|
|
anchor = Anchor.center;
|
|
}
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
super.onLoad();
|
|
sprite = await gameRef.loadSprite('layers/player.png');
|
|
position = gameRef.size / 2;
|
|
}
|
|
|
|
@override
|
|
void update(double dt) {
|
|
if (!joystick.delta.isZero()) {
|
|
position.add(joystick.relativeDelta * maxSpeed * dt);
|
|
angle = joystick.delta.screenAngle();
|
|
}
|
|
}
|
|
}
|