pantin

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::load reads 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_bundle reads the bundle pantin build writes.
  • 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 reads state(); each state entered comes as a StateMessage. play by 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; None gives it back to the keys.
  • PantinPlugin plays every Character each frame: its player (a pantin_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 triangles pantin_runtime::draw::shapes gives, the one pantin render draws.
  • What an animation tells comes as AnimationEvent messages, with the sound of 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, as BoxMessages. Character::boxes gives the boxes active now with their corners in the world of Bevy, and pantin_runtime::hit::overlap tests 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.