From 3d9448e20e22d2cc2dba7c33f812b763546b49c4 Mon Sep 17 00:00:00 2001 From: rafaelbarbosatec Date: Mon, 22 Jun 2020 15:51:18 -0300 Subject: [PATCH] improvements code --- example/lib/main.dart | 3 --- lib/components/joystick/Joystick_action.dart | 25 ++++++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 5357aa93f..98b552ae6 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -102,9 +102,6 @@ class MyGame extends BaseGame @override void joystickAction(JoystickActionEvent event) { - if (event.id == 2 && event.event == ActionEvent.DOWN) { - onTap(); - } print(event); } diff --git a/lib/components/joystick/Joystick_action.dart b/lib/components/joystick/Joystick_action.dart index a67586da6..99ce60681 100644 --- a/lib/components/joystick/Joystick_action.dart +++ b/lib/components/joystick/Joystick_action.dart @@ -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; }