mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-12 02:19:49 +08:00
improvements code
This commit is contained in:
@@ -102,9 +102,6 @@ class MyGame extends BaseGame
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void joystickAction(JoystickActionEvent event) {
|
void joystickAction(JoystickActionEvent event) {
|
||||||
if (event.id == 2 && event.event == ActionEvent.DOWN) {
|
|
||||||
onTap();
|
|
||||||
}
|
|
||||||
print(event);
|
print(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class JoystickAction {
|
|||||||
final bool enableDirection;
|
final bool enableDirection;
|
||||||
final Color color;
|
final Color color;
|
||||||
|
|
||||||
|
bool isPressed = false;
|
||||||
Rect _rectAction;
|
Rect _rectAction;
|
||||||
Rect _rectBackgroundDirection;
|
Rect _rectBackgroundDirection;
|
||||||
bool _dragging = false;
|
bool _dragging = false;
|
||||||
@@ -28,6 +29,7 @@ class JoystickAction {
|
|||||||
Offset _dragPosition;
|
Offset _dragPosition;
|
||||||
Paint _paintBackground;
|
Paint _paintBackground;
|
||||||
Paint _paintAction;
|
Paint _paintAction;
|
||||||
|
Paint _paintActionPressed;
|
||||||
JoystickController _joystickController;
|
JoystickController _joystickController;
|
||||||
double _sizeBackgroundDirection;
|
double _sizeBackgroundDirection;
|
||||||
DragEvent _currentDragEvent;
|
DragEvent _currentDragEvent;
|
||||||
@@ -79,14 +81,21 @@ class JoystickAction {
|
|||||||
radius: _sizeBackgroundDirection / 2,
|
radius: _sizeBackgroundDirection / 2,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (spriteBackgroundDirection == null)
|
||||||
_paintBackground = Paint()
|
_paintBackground = Paint()
|
||||||
..color = color.withOpacity(0.5)
|
..color = color.withOpacity(0.5)
|
||||||
..style = PaintingStyle.fill;
|
..style = PaintingStyle.fill;
|
||||||
|
|
||||||
|
if (sprite == null)
|
||||||
_paintAction = Paint()
|
_paintAction = Paint()
|
||||||
..color = color.withOpacity(0.8)
|
..color = color.withOpacity(0.8)
|
||||||
..style = PaintingStyle.fill;
|
..style = PaintingStyle.fill;
|
||||||
|
|
||||||
|
if (spritePressed == null)
|
||||||
|
_paintActionPressed = Paint()
|
||||||
|
..color = color.withOpacity(0.5)
|
||||||
|
..style = PaintingStyle.fill;
|
||||||
|
|
||||||
_dragPosition = _rectAction.center;
|
_dragPosition = _rectAction.center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +128,7 @@ class JoystickAction {
|
|||||||
_rectAction.top + radiusAction,
|
_rectAction.top + radiusAction,
|
||||||
),
|
),
|
||||||
radiusAction,
|
radiusAction,
|
||||||
_paintAction,
|
isPressed ? _paintActionPressed : _paintAction,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,12 +207,14 @@ class JoystickAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pressed() {
|
void pressed() {
|
||||||
|
isPressed = true;
|
||||||
if (spritePressed != null) {
|
if (spritePressed != null) {
|
||||||
_spriteAction = spritePressed;
|
_spriteAction = spritePressed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void unPressed() {
|
void unPressed() {
|
||||||
|
isPressed = false;
|
||||||
_spriteAction = sprite;
|
_spriteAction = sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user