mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
31 lines
684 B
Dart
31 lines
684 B
Dart
import 'dart:ui';
|
|
|
|
import '../../sprite.dart';
|
|
import '../../extensions/offset.dart';
|
|
import '../../extensions/size.dart';
|
|
|
|
class JoystickUtils {
|
|
static void renderControl(Canvas c, Sprite sprite, Rect rect, Paint paint) {
|
|
if (rect == null) {
|
|
return;
|
|
}
|
|
|
|
if (sprite == null) {
|
|
assert(paint != null, '`paint` must not be `null` if `sprite` is `null`');
|
|
|
|
final double radius = rect.width / 2;
|
|
c.drawCircle(
|
|
Offset(rect.left + radius, rect.top + radius),
|
|
radius,
|
|
paint,
|
|
);
|
|
} else {
|
|
sprite.render(
|
|
c,
|
|
position: rect.topLeft.toVector2(),
|
|
size: rect.size.toVector2(),
|
|
);
|
|
}
|
|
}
|
|
}
|