[flutter] Play/pause example.

This commit is contained in:
Mario Zechner 2022-11-15 11:48:01 +01:00
parent e526619e96
commit 70933889ed
13 changed files with 3448 additions and 1908 deletions

View File

@ -95,6 +95,9 @@ cp -f ../spineboy/export/spineboy-pro.json "$ROOT/spine-flutter/example/assets/"
cp -f ../spineboy/export/spineboy-pro.skel "$ROOT/spine-flutter/example/assets/"
cp -f ../spineboy/export/spineboy.atlas "$ROOT/spine-flutter/example/assets/"
cp -f ../spineboy/export/spineboy.png "$ROOT/spine-flutter/example/assets/"
cp -f ../mix-and-match/export/mix-and-match-pro.skel "$ROOT/spine-flutter/example/assets/"
cp -f ../mix-and-match/export/mix-and-match.atlas "$ROOT/spine-flutter/example/assets/"
cp -f ../mix-and-match/export/mix-and-match.png "$ROOT/spine-flutter/example/assets/"
echo "spine-godot"
rm -f "$ROOT"/spine-godot/example/assets/spineboy/*.atlas

Binary file not shown.

View File

@ -0,0 +1,362 @@
mix-and-match.png
size: 1024, 512
filter: Linear, Linear
scale: 0.5
base-head
bounds: 587, 2, 95, 73
boy/arm-front
bounds: 558, 271, 36, 115
boy/backpack
bounds: 235, 109, 119, 153
boy/backpack-pocket
bounds: 328, 73, 34, 62
rotate: 90
boy/backpack-strap-front
bounds: 665, 79, 38, 88
boy/backpack-up
bounds: 395, 364, 21, 70
rotate: 90
boy/body
bounds: 251, 264, 97, 132
rotate: 90
boy/boot-ribbon-front
bounds: 648, 131, 9, 11
boy/collar
bounds: 744, 4, 73, 29
rotate: 90
boy/ear
bounds: 383, 109, 19, 23
rotate: 90
boy/eye-back-low-eyelid
bounds: 739, 284, 17, 6
rotate: 90
boy/eye-back-pupil
bounds: 832, 443, 8, 9
rotate: 90
boy/eye-back-up-eyelid
bounds: 558, 264, 23, 5
boy/eye-back-up-eyelid-back
bounds: 802, 491, 19, 10
rotate: 90
boy/eye-front-low-eyelid
bounds: 386, 363, 22, 7
rotate: 90
boy/eye-front-pupil
bounds: 816, 389, 9, 9
boy/eye-front-up-eyelid
bounds: 160, 71, 31, 6
rotate: 90
boy/eye-front-up-eyelid-back
bounds: 801, 434, 26, 9
rotate: 90
boy/eye-iris-back
bounds: 618, 264, 17, 17
boy/eye-iris-front
bounds: 727, 264, 18, 18
boy/eye-white-back
bounds: 580, 131, 20, 12
boy/eye-white-front
bounds: 510, 130, 27, 13
boy/eyebrow-back
bounds: 751, 88, 20, 11
rotate: 90
boy/eyebrow-front
bounds: 483, 130, 25, 11
boy/hair-back
bounds: 494, 388, 122, 81
rotate: 90
boy/hair-bangs
bounds: 667, 284, 70, 37
boy/hair-side
bounds: 789, 374, 25, 43
boy/hand-backfingers
bounds: 467, 364, 19, 21
boy/hand-front-fingers
bounds: 488, 364, 19, 21
boy/hat
bounds: 615, 417, 93, 56
rotate: 90
boy/leg-front
bounds: 138, 104, 31, 158
boy/mouth-close
bounds: 551, 365, 21, 5
rotate: 90
girl-blue-cape/mouth-close
bounds: 551, 365, 21, 5
rotate: 90
girl-spring-dress/mouth-close
bounds: 551, 365, 21, 5
rotate: 90
girl/mouth-close
bounds: 551, 365, 21, 5
rotate: 90
boy/mouth-smile
bounds: 705, 79, 29, 7
boy/nose
bounds: 836, 473, 17, 10
rotate: 90
boy/pompom
bounds: 747, 273, 48, 43
rotate: 90
boy/zip
bounds: 648, 144, 14, 23
girl-blue-cape/back-eyebrow
bounds: 602, 131, 18, 12
girl-blue-cape/body-dress
bounds: 2, 264, 109, 246
girl-blue-cape/body-ribbon
bounds: 615, 283, 50, 38
girl-blue-cape/cape-back
bounds: 2, 69, 134, 193
girl-blue-cape/cape-back-up
bounds: 386, 387, 123, 106
rotate: 90
girl-blue-cape/cape-ribbon
bounds: 675, 264, 50, 18
girl-blue-cape/cape-shoulder-back
bounds: 751, 110, 49, 59
girl-blue-cape/cape-shoulder-front
bounds: 113, 264, 62, 76
rotate: 90
girl-blue-cape/cape-up-front
bounds: 399, 264, 98, 117
rotate: 90
girl-blue-cape/ear
bounds: 775, 2, 19, 23
girl-spring-dress/ear
bounds: 775, 2, 19, 23
girl/ear
bounds: 775, 2, 19, 23
girl-blue-cape/eye-back-low-eyelid
bounds: 802, 463, 17, 6
girl-spring-dress/eye-back-low-eyelid
bounds: 802, 463, 17, 6
girl/eye-back-low-eyelid
bounds: 802, 463, 17, 6
girl-blue-cape/eye-back-pupil
bounds: 816, 367, 8, 9
girl-spring-dress/eye-back-pupil
bounds: 816, 367, 8, 9
girl/eye-back-pupil
bounds: 816, 367, 8, 9
girl-blue-cape/eye-back-up-eyelid
bounds: 554, 131, 24, 12
girl-spring-dress/eye-back-up-eyelid
bounds: 554, 131, 24, 12
girl/eye-back-up-eyelid
bounds: 554, 131, 24, 12
girl-blue-cape/eye-back-up-eyelid-back
bounds: 832, 453, 17, 11
rotate: 90
girl-spring-dress/eye-back-up-eyelid-back
bounds: 832, 453, 17, 11
rotate: 90
girl/eye-back-up-eyelid-back
bounds: 832, 453, 17, 11
rotate: 90
girl-blue-cape/eye-front-low-eyelid
bounds: 739, 303, 18, 6
rotate: 90
girl-spring-dress/eye-front-low-eyelid
bounds: 739, 303, 18, 6
rotate: 90
girl/eye-front-low-eyelid
bounds: 739, 303, 18, 6
rotate: 90
girl-blue-cape/eye-front-pupil
bounds: 816, 378, 9, 9
girl-spring-dress/eye-front-pupil
bounds: 816, 378, 9, 9
girl/eye-front-pupil
bounds: 816, 378, 9, 9
girl-blue-cape/eye-front-up-eyelid
bounds: 392, 77, 30, 14
rotate: 90
girl-spring-dress/eye-front-up-eyelid
bounds: 392, 77, 30, 14
rotate: 90
girl/eye-front-up-eyelid
bounds: 392, 77, 30, 14
rotate: 90
girl-blue-cape/eye-front-up-eyelid-back
bounds: 455, 130, 26, 11
girl-spring-dress/eye-front-up-eyelid-back
bounds: 455, 130, 26, 11
girl/eye-front-up-eyelid-back
bounds: 455, 130, 26, 11
girl-blue-cape/eye-iris-back
bounds: 637, 264, 17, 17
girl-blue-cape/eye-iris-front
bounds: 802, 471, 18, 18
girl-blue-cape/eye-white-back
bounds: 596, 264, 20, 16
girl-spring-dress/eye-white-back
bounds: 596, 264, 20, 16
girl-blue-cape/eye-white-front
bounds: 796, 5, 20, 16
rotate: 90
girl-spring-dress/eye-white-front
bounds: 796, 5, 20, 16
rotate: 90
girl/eye-white-front
bounds: 796, 5, 20, 16
rotate: 90
girl-blue-cape/front-eyebrow
bounds: 608, 149, 18, 12
rotate: 90
girl-blue-cape/hair-back
bounds: 508, 145, 117, 98
rotate: 90
girl-blue-cape/hair-bangs
bounds: 673, 419, 91, 40
rotate: 90
girl-blue-cape/hair-head-side-back
bounds: 196, 331, 30, 52
rotate: 90
girl-blue-cape/hair-head-side-front
bounds: 738, 323, 41, 42
girl-blue-cape/hair-side
bounds: 473, 3, 36, 71
girl-blue-cape/hand-front-fingers
bounds: 509, 365, 19, 21
girl-spring-dress/hand-front-fingers
bounds: 509, 365, 19, 21
girl-blue-cape/leg-front
bounds: 168, 72, 30, 158
rotate: 90
girl-blue-cape/mouth-smile
bounds: 736, 79, 29, 7
girl-spring-dress/mouth-smile
bounds: 736, 79, 29, 7
girl/mouth-smile
bounds: 736, 79, 29, 7
girl-blue-cape/nose
bounds: 747, 264, 11, 7
girl-spring-dress/nose
bounds: 747, 264, 11, 7
girl/nose
bounds: 747, 264, 11, 7
girl-blue-cape/sleeve-back
bounds: 767, 79, 42, 29
girl-blue-cape/sleeve-front
bounds: 408, 76, 52, 119
rotate: 90
girl-spring-dress/arm-front
bounds: 596, 282, 17, 111
girl-spring-dress/back-eyebrow
bounds: 801, 420, 18, 12
girl-spring-dress/body-up
bounds: 179, 4, 64, 66
girl-spring-dress/cloak-down
bounds: 775, 27, 50, 50
girl-spring-dress/cloak-up
bounds: 360, 7, 64, 58
rotate: 90
girl-spring-dress/eye-iris-back
bounds: 656, 264, 17, 17
girl-spring-dress/eye-iris-front
bounds: 814, 492, 18, 18
girl-spring-dress/front-eyebrow
bounds: 822, 472, 18, 12
rotate: 90
girl-spring-dress/hair-back
bounds: 196, 363, 147, 93
rotate: 90
girl-spring-dress/hair-bangs
bounds: 696, 326, 91, 40
rotate: 90
girl-spring-dress/hair-head-side-back
bounds: 529, 76, 30, 52
girl-spring-dress/hair-head-side-front
bounds: 781, 323, 41, 42
girl-spring-dress/hair-side
bounds: 511, 3, 36, 71
girl-spring-dress/leg-front
bounds: 171, 104, 30, 158
girl-spring-dress/neck
bounds: 138, 70, 20, 32
girl-spring-dress/shoulder-ribbon
bounds: 622, 131, 36, 24
rotate: 90
girl-spring-dress/skirt
bounds: 113, 328, 182, 81
rotate: 90
girl-spring-dress/underskirt
bounds: 2, 2, 175, 65
girl/arm-front
bounds: 577, 395, 36, 115
girl/back-eyebrow
bounds: 834, 492, 18, 12
rotate: 90
girl/bag-base
bounds: 191, 264, 62, 58
rotate: 90
girl/bag-strap-front
bounds: 385, 265, 12, 96
girl/bag-top
bounds: 738, 367, 49, 50
girl/body
bounds: 356, 130, 97, 132
girl/boot-ribbon-front
bounds: 539, 130, 13, 13
girl/eye-iris-back
bounds: 821, 424, 17, 17
girl/eye-iris-front
bounds: 812, 443, 18, 18
girl/eye-white-back
bounds: 814, 5, 20, 16
rotate: 90
girl/front-eyebrow
bounds: 816, 400, 18, 12
rotate: 90
girl/hair-back
bounds: 291, 363, 147, 93
rotate: 90
girl/hair-bangs
bounds: 715, 419, 91, 40
rotate: 90
girl/hair-flap-down-front
bounds: 288, 5, 70, 65
girl/hair-head-side-back
bounds: 561, 77, 30, 52
girl/hair-head-side-front
bounds: 757, 419, 41, 42
rotate: 90
girl/hair-patch
bounds: 245, 4, 66, 41
rotate: 90
girl/hair-side
bounds: 549, 3, 36, 71
girl/hair-strand-back-1
bounds: 684, 3, 58, 74
girl/hair-strand-back-2
bounds: 692, 171, 91, 58
rotate: 90
girl/hair-strand-back-3
bounds: 615, 323, 92, 79
rotate: 90
girl/hair-strand-front-1
bounds: 518, 269, 38, 94
girl/hair-strand-front-2
bounds: 593, 79, 70, 50
girl/hair-strand-front-3
bounds: 705, 88, 44, 81
girl/hand-front-fingers
bounds: 530, 365, 19, 21
girl/hat
bounds: 608, 169, 93, 82
rotate: 90
girl/leg-front
bounds: 203, 104, 30, 158
girl/pompom
bounds: 757, 462, 48, 43
rotate: 90
girl/scarf
bounds: 455, 143, 119, 51
rotate: 90
girl/scarf-back
bounds: 420, 2, 72, 51
rotate: 90
girl/zip
bounds: 356, 109, 19, 25
rotate: 90

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 KiB

View File

@ -1,6 +0,0 @@
skeleton.png
size:188,198
filter:Linear,Linear
pma:true
Screenshot 2022-08-19 at 13.45.53
bounds:2,2,184,194

View File

@ -1,40 +0,0 @@
{
"skeleton": {
"hash": "EzIWQLMq9sw",
"spine": "4.1.08",
"x": -92,
"y": -97,
"width": 184,
"height": 194,
"images": "",
"audio": ""
},
"bones": [
{
"name": "root"
}
],
"slots": [
{
"name": "image",
"bone": "root",
"attachment": "Screenshot 2022-08-19 at 13.45.53"
}
],
"skins": [
{
"name": "default",
"attachments": {
"image": {
"Screenshot 2022-08-19 at 13.45.53": {
"width": 184,
"height": 194
}
}
}
}
],
"animations": {
"animation": {}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

View File

@ -23,6 +23,18 @@ class ExampleSelector extends StatelessWidget {
},
),
spacer,
ElevatedButton(
child: const Text('Pause/Play animation'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (context) => const PlayPauseAnimation(),
),
);
},
),
spacer,
ElevatedButton(
child: const Text('Animation State Listener'),
onPressed: () {
@ -50,15 +62,53 @@ class SimpleAnimation extends StatelessWidget {
reportLeaks();
final controller = SpineWidgetController((controller) {
// Set the walk animation on track 0, let it loop
controller.animationState?.setAnimationByName(0, "animation", true);
controller.animationState?.setAnimationByName(0, "walk", true);
});
return Scaffold(
appBar: AppBar(title: const Text('Spineboy')),
body: SpineWidget.asset("assets/skeleton.json", "assets/skeleton.atlas", controller, alignment: Alignment.topLeft, fit: BoxFit.cover),
// body: SpineWidget.asset("assets/spineboy-pro.skel", "assets/spineboy.atlas", controller, alignment: Alignment.bottomLeft)
body: SpineWidget.asset("assets/spineboy-pro.skel", "assets/spineboy.atlas", controller),
// body: SpineWidget.file("/Users/badlogic/workspaces/spine-runtimes/examples/spineboy/export/spineboy-pro.skel", "/Users/badlogic/workspaces/spine-runtimes/examples/spineboy/export/spineboy.atlas", controller),
// body: const SpineWidget.http("https://marioslab.io/dump/spineboy/spineboy-pro.json", "https://marioslab.io/dump/spineboy/spineboy.atlas"),
// body: SpineWidget.asset("assets/skeleton.json", "assets/skeleton.atlas", controller, alignment: Alignment.topLeft, fit: BoxFit.cover),
);
}
}
class PlayPauseAnimation extends StatefulWidget {
const PlayPauseAnimation({Key? key}) : super(key: key);
@override
PlayPauseAnimationState createState() => PlayPauseAnimationState();
}
class PlayPauseAnimationState extends State<PlayPauseAnimation> {
late SpineWidgetController _controller;
@override
void initState() {
super.initState();
_controller = SpineWidgetController((controller) {
controller.animationState?.setAnimationByName(0, "walk", true);
});
}
void _togglePlaystate() {
_controller.togglePlay();
setState(() {});
}
@override
Widget build(BuildContext context) {
reportLeaks();
return Scaffold(
appBar: AppBar(title: const Text('Spineboy')),
body: SpineWidget.asset("assets/spineboy-pro.skel", "assets/spineboy.atlas", _controller),
floatingActionButton: FloatingActionButton(
onPressed: _togglePlaystate,
child: Icon(_controller.isPlaying ? Icons.pause : Icons.play_arrow),
),
);
}
}

View File

@ -3097,6 +3097,10 @@ class AnimationState {
return TrackEntry._(entry, this);
}
int getNumTracks() {
return _bindings.spine_animation_state_get_num_tracks(_state);
}
/// Sets an empty animation for every track, discarding any queued animations, and mixes to it over the specified mix duration.
void setEmptyAnimations(double mixDuration) {
_bindings.spine_animation_state_set_empty_animations(_state, mixDuration);

File diff suppressed because it is too large Load Diff

View File

@ -38,6 +38,36 @@ class SpineWidgetController {
AnimationState? get animationState => _drawable?.animationState;
Skeleton? get skeleton => _drawable?.skeleton;
void pause() {
_drawable?.animationState.setTimeScale(0);
}
void play() {
_drawable?.animationState.setTimeScale(1);
}
void togglePlay() {
_drawable?.animationState.setTimeScale(isPlaying ? 0 : 1);
}
bool get isPlaying => _drawable?.animationState.getTimeScale() != 0;
List<String> get animationNames {
List<String> names = [];
for (var anim in _drawable?.skeletonData.getAnimations() ?? []) {
names.add(anim.getName());
}
return names;
}
List<String> get skinNames {
List<String> names = [];
for (var skin in _drawable?.skeletonData.getSkins() ?? []) {
names.add(skin.getName());
}
return names;
}
}
enum AssetType { Asset, File, Http, Raw }

View File

@ -641,6 +641,12 @@ FFI_PLUGIN_EXPORT void spine_animation_state_clear_tracks(spine_animation_state
_state->clearTracks();
}
FFI_PLUGIN_EXPORT int spine_animation_state_get_num_tracks(spine_animation_state state) {
if (state == nullptr) return 0;
AnimationState *_state = (AnimationState*)state;
return (int) _state->getTracks().size();
}
FFI_PLUGIN_EXPORT void spine_animation_state_clear_track(spine_animation_state state, int trackIndex) {
if (state == nullptr) return;
AnimationState *_state = (AnimationState*)state;

View File

@ -283,6 +283,7 @@ FFI_PLUGIN_EXPORT void spine_animation_state_update(spine_animation_state state,
FFI_PLUGIN_EXPORT void spine_animation_state_apply(spine_animation_state state, spine_skeleton skeleton);
FFI_PLUGIN_EXPORT void spine_animation_state_clear_tracks(spine_animation_state state);
FFI_PLUGIN_EXPORT void spine_animation_state_clear_track(spine_animation_state state, int trackIndex);
FFI_PLUGIN_EXPORT int spine_animation_state_get_num_tracks(spine_animation_state state);
FFI_PLUGIN_EXPORT spine_track_entry spine_animation_state_set_animation_by_name(spine_animation_state state, int trackIndex, const char* animationName, int loop);
FFI_PLUGIN_EXPORT spine_track_entry spine_animation_state_set_animation(spine_animation_state state, int trackIndex, spine_animation animation, int loop);
FFI_PLUGIN_EXPORT spine_track_entry spine_animation_state_add_animation_by_name(spine_animation_state state, int trackIndex, const char* animationName, int loop, float delay);