mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-10 00:58:43 +08:00
[flutter] More work on dress-up example.
This commit is contained in:
parent
a3874256cd
commit
187808d543
@ -1,3 +1,4 @@
|
||||
import 'dart:math';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@ -21,27 +22,30 @@ class DressUpState extends State<DressUp> {
|
||||
super.initState();
|
||||
SkeletonDrawable.fromAsset("assets/mix-and-match-pro.skel", "assets/mix-and-match.atlas").then((drawable) async {
|
||||
for (var skin in drawable.skeletonData.getSkins()) {
|
||||
//if (skin.getName() == "default") continue;
|
||||
if (skin.getName() == "default") continue;
|
||||
|
||||
var skeleton = drawable.skeleton;
|
||||
skeleton.setSkin(skin);
|
||||
skeleton.setToSetupPose();
|
||||
skeleton.updateWorldTransform();
|
||||
var bounds = skeleton.getBounds();
|
||||
var scale = 1 / (bounds.width > bounds.height ? bounds.width / thumbnailSize * 1.1 : bounds.height / thumbnailSize * 1.1);
|
||||
var scale = 1 / (bounds.width > bounds.height ? bounds.width / thumbnailSize : bounds.height / thumbnailSize);
|
||||
scale *= 0.9;
|
||||
|
||||
var recorder = ui.PictureRecorder();
|
||||
var canvas = Canvas(recorder, const Rect.fromLTWH(0, 0, thumbnailSize, thumbnailSize));
|
||||
var canvas = Canvas(recorder);
|
||||
var bgColor = Random().nextInt(0xffffffff) | 0xff0000000;
|
||||
var paint = Paint()
|
||||
..color = const ui.Color(0xffff00ff)
|
||||
..color = ui.Color(bgColor)
|
||||
..style = PaintingStyle.fill;
|
||||
canvas.drawRect(const Rect.fromLTWH(0, 0, thumbnailSize, thumbnailSize), paint);
|
||||
canvas.scale(scale, scale);
|
||||
canvas.translate(-bounds.x, -bounds.y);
|
||||
canvas.drawRect(Rect.fromLTRB(-5, -5, 5, -5), paint..color = Colors.red);
|
||||
drawable.renderToCanvas(canvas);
|
||||
|
||||
var imageData = await (await recorder.endRecording().toImage(thumbnailSize.toInt(), thumbnailSize.toInt())).toByteData(format: ui.ImageByteFormat.png);
|
||||
_skinImages.add(Image.memory(imageData!.buffer.asUint8List(), fit: BoxFit.none));
|
||||
_skinImages.add(Image.memory(imageData!.buffer.asUint8List(), fit: BoxFit.contain));
|
||||
}
|
||||
_drawable = drawable;
|
||||
setState(() {});
|
||||
@ -59,7 +63,7 @@ class DressUpState extends State<DressUp> {
|
||||
Expanded(
|
||||
child:ListView(
|
||||
children: _skinImages.map((image) {
|
||||
return SizedBox(width: 100, height: 100, child: image);
|
||||
return SizedBox(width: 200, height: 200, child: image);
|
||||
}).toList()
|
||||
)
|
||||
),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user