improvements code

This commit is contained in:
rafaelbarbosatec
2020-06-22 15:51:18 -03:00
parent 2ee76e7cbf
commit 3d9448e20e
2 changed files with 18 additions and 10 deletions

View File

@ -102,9 +102,6 @@ class MyGame extends BaseGame
@override
void joystickAction(JoystickActionEvent event) {
if (event.id == 2 && event.event == ActionEvent.DOWN) {
onTap();
}
print(event);
}

View File

@ -21,6 +21,7 @@ class JoystickAction {
final bool enableDirection;
final Color color;
bool isPressed = false;
Rect _rectAction;
Rect _rectBackgroundDirection;
bool _dragging = false;
@ -28,6 +29,7 @@ class JoystickAction {
Offset _dragPosition;
Paint _paintBackground;
Paint _paintAction;
Paint _paintActionPressed;
JoystickController _joystickController;
double _sizeBackgroundDirection;
DragEvent _currentDragEvent;
@ -79,13 +81,20 @@ class JoystickAction {
radius: _sizeBackgroundDirection / 2,
);
_paintBackground = Paint()
..color = color.withOpacity(0.5)
..style = PaintingStyle.fill;
if (spriteBackgroundDirection == null)
_paintBackground = Paint()
..color = color.withOpacity(0.5)
..style = PaintingStyle.fill;
_paintAction = Paint()
..color = color.withOpacity(0.8)
..style = PaintingStyle.fill;
if (sprite == null)
_paintAction = Paint()
..color = color.withOpacity(0.8)
..style = PaintingStyle.fill;
if (spritePressed == null)
_paintActionPressed = Paint()
..color = color.withOpacity(0.5)
..style = PaintingStyle.fill;
_dragPosition = _rectAction.center;
}
@ -119,7 +128,7 @@ class JoystickAction {
_rectAction.top + radiusAction,
),
radiusAction,
_paintAction,
isPressed ? _paintActionPressed : _paintAction,
);
}
}
@ -198,12 +207,14 @@ class JoystickAction {
}
void pressed() {
isPressed = true;
if (spritePressed != null) {
_spriteAction = spritePressed;
}
}
void unPressed() {
isPressed = false;
_spriteAction = sprite;
}