This page is runtimes/bevy/README.md of the repository, as it is on main.
pantin-bevy
Plays pantin characters in Bevy 0.20.
use bevy::prelude::*;
use pantin_bevy::{Character, PantinPlugin};
fn main() {
App::new()
.add_plugins((DefaultPlugins, PantinPlugin))
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
commands.spawn(Camera2d);
let mut hero = Character::load("hero.pantin".as_ref(), &mut images).unwrap();
hero.play(0, "walk", 0.0);
commands.spawn((hero, Transform::from_scale(Vec3::splat(2.0))));
}
Character::loadreads the folder of a project: its skeleton and animations (rig.json), its images, PNG or SVG, made textures, its boxes (hit.json) and its graph of states (flow.json);Character::load_bundlereads the bundlepantin buildwrites.- A character whose project has a graph follows it from its entry: the game sets its parameters
(
set_number,set_switch), fires its triggers (fire("jump")) and readsstate(); each state entered comes as aStateMessage.playby name leaves the graph. Character::set_slider(name, Some(time))sets the time of a slider over its keys: the character takes the pose its animation has then;Nonegives it back to the keys.PantinPluginplays everyCharactereach frame: itsplayer(apantin_runtime::Player: tracks, weights, fades,play(track, name, fade)), its springs, and draws it as 2D meshes, children of its entity, from the list of trianglespantin_runtime::draw::shapesgives, the onepantin renderdraws.- What an animation tells comes as
AnimationEventmessages, with thesoundof the event when it has one (its file, relative to the project, its volume and its balance) for the game to play; the start and the end of a range of a box that asks for its events, asBoxMessages.Character::boxesgives the boxes active now with their corners in the world of Bevy, andpantin_runtime::hit::overlaptests two. - One unit of pantin is one unit of Bevy, y up. The blend modes other than normal, and the dark colour, are drawn as normal for now.
It is a workspace of its own, apart from the one of the editor, so that the editor does not
build Bevy: run cargo test and cargo run --example walk from this folder. The example plays
the stickman of examples/ walking and the robot following its graph, told hello every three
seconds, and writes in the log what they tell.