반응형
리벳의 상태 기계를 펄럭이는 방법은 무엇입니까?
저는 "상태 기계"에 있는 시작, 처리, 종료의 세 가지 상태 애니메이션으로 .riv 파일을 만들었습니다. 리브 팀은 최근 역동적으로 변화하는 애니메이션과 함께 새로운 기능인 "상태 기계"를 발표했습니다. Floating 프로젝트에서 어떻게 사용하는지, 즉 애니메이션의 가치를 동적으로 변경하는지 확실하지 않다. 코드가 필요한 사람이 있다면 문제없어요, 제가 제공할 수 있습니다. 게다가, 리벳의 "상태 기계"에 링크. 나는 이 새로운 기능과 관련된 어떤 예도 찾지 못했다. 도와주세요! 감사해요.
If you are having SMIInput in your Animation them follow this code below:
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
SMIInput<double>? _input;
StateMachineController? controller;
double val = 0;
void _onRiveInit(Artboard artboard) {
controller =
StateMachineController.fromArtboard(artboard, 'State Machine 1');
artboard.addController(controller!);
_input = controller?.findInput<double>('input') as SMINumber;
_input?.change(val);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Simple Animation'),
),
body: Center(
child: SizedBox(
width: 200.0,
child: GestureDetector(
child: RiveAnimation.asset(
'assets/rive/loading_state.riv',
fit: BoxFit.fitWidth,
onInit: (art) {
_onRiveInit(art);
},
),
onTap: () {
val++;
_input?.change(val);
},
),
),
));
}
}
There are examples on rives pub package site. Here is one for state machine. example_state_machine.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:rive/rive.dart';
/// An example showing how to drive two boolean state machine inputs.
class ExampleStateMachine extends StatefulWidget {
const ExampleStateMachine({Key? key}) : super(key: key);
@override
_ExampleStateMachineState createState() => _ExampleStateMachineState();
}
class _ExampleStateMachineState extends State<ExampleStateMachine> {
/// Tracks if the animation is playing by whether controller is running.
bool get isPlaying => _controller?.isActive ?? false;
Artboard? _riveArtboard;
StateMachineController? _controller;
SMIInput<bool>? _hoverInput;
SMIInput<bool>? _pressInput;
@override
void initState() {
super.initState();
// Load the animation file from the bundle, note that you could also
// download this. The RiveFile just expects a list of bytes.
rootBundle.load('assets/rocket.riv').then(
(data) async {
// Load the RiveFile from the binary data.
final file = RiveFile.import(data);
// The artboard is the root of the animation and gets drawn in the
// Rive widget.
final artboard = file.mainArtboard;
var controller =
StateMachineController.fromArtboard(artboard, 'Button');
if (controller != null) {
artboard.addController(controller);
_hoverInput = controller.findInput('Hover');
_pressInput = controller.findInput('Press');
}
setState(() => _riveArtboard = artboard);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
title: const Text('Button State Machine'),
),
body: Center(
child: _riveArtboard == null
? const SizedBox()
: MouseRegion(
onEnter: (_) => _hoverInput?.value = true,
onExit: (_) => _hoverInput?.value = false,
child: GestureDetector(
onTapDown: (_) => _pressInput?.value = true,
onTapCancel: () => _pressInput?.value = false,
onTapUp: (_) => _pressInput?.value = false,
child: SizedBox(
width: 250,
height: 250,
child: Rive(
artboard: _riveArtboard!,
),
),
),
),
),
);
}
}
The other answer is outdated.
class SimpleStateMachine extends StatefulWidget {
const SimpleStateMachine({Key? key}) : super(key: key);
@override
_SimpleStateMachineState createState() => _SimpleStateMachineState();
}
class _SimpleStateMachineState extends State<SimpleStateMachine> {
SMITrigger? _bump;
void _onRiveInit(Artboard artboard) {
final controller = StateMachineController.fromArtboard(artboard, 'bumpy');
artboard.addController(controller!);
_bump = controller.findInput<bool>('bump') as SMITrigger;
}
void _hitBump() => _bump?.fire();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Simple Animation'),
),
body: Center(
child: GestureDetector(
child: RiveAnimation.network(
'https://cdn.rive.app/animations/vehicles.riv',
fit: BoxFit.cover,
onInit: _onRiveInit,
),
onTap: _hitBump,
),
),
);
}
}
See the RIVE guide:
https://help.rive.app/runtimes/state-machines
반응형
'개발하자' 카테고리의 다른 글
Svelte/Typescript 오류: 형식 선언 중 "예상치 못한 토큰" (0) | 2023.05.01 |
---|---|
FastAPI: 멀티파트/폼 데이터 요청을 사용하지 않고 파일을 업로드하는 방법은 무엇입니까? (0) | 2023.05.01 |
FastAPI: "ImportError: 알려진 상위 패키지가 없는 상대 가져오기 시도" (0) | 2023.04.30 |
TypeScript는 내보내기 선언 대신 정의된 선언이 있는 .d.ts 파일을 생성합니다 (0) | 2023.04.29 |
Float - 눌린 상태의 용기? (0) | 2023.04.29 |