Struct rusty_spine::SkeletonJson
source · pub struct SkeletonJson { /* private fields */ }
Expand description
A loader for Spine json files.
Implementations§
source§impl SkeletonJson
impl SkeletonJson
sourcepub fn new(atlas: Arc<Atlas>) -> Self
pub fn new(atlas: Arc<Atlas>) -> Self
Create a new JSON loader using the default atlas attachment loader.
use std::sync::Arc;
use rusty_spine::{AnimationState, AnimationStateData, Atlas, SpineError, Skeleton, SkeletonJson};
fn load_skeleton() -> Result<(Skeleton, AnimationState), SpineError> {
let atlas = Arc::new(Atlas::new_from_file("spineboy.atlas")?);
let skeleton_json = SkeletonJson::new(atlas);
let skeleton_data = Arc::new(skeleton_json.read_skeleton_data_file("spineboy.json")?);
let animation_state_data = AnimationStateData::new(skeleton_data.clone());
// ... prepare animation state (see AnimationStateData docs) ...
let skeleton = Skeleton::new(skeleton_data);
let animation_state = AnimationState::new(Arc::new(animation_state_data));
Ok((skeleton, animation_state))
}
sourcepub fn read_skeleton_data(
&self,
json: &[u8]
) -> Result<SkeletonData, SpineError>
pub fn read_skeleton_data( &self, json: &[u8] ) -> Result<SkeletonData, SpineError>
Read the Spine skeleton json data in-memory. See SkeletonJson::new
for a full example.
§Errors
Returns SpineError::ParsingFailed
if parsing of the json data failed.
sourcepub fn read_skeleton_data_file<P: AsRef<Path>>(
&self,
path: P
) -> Result<SkeletonData, SpineError>
pub fn read_skeleton_data_file<P: AsRef<Path>>( &self, path: P ) -> Result<SkeletonData, SpineError>
Read the Spine skeleton json data from a file. See SkeletonJson::new
for a full example.
§Errors
Returns SpineError::ParsingFailed
if parsing of the json data failed. Returns
SpineError::NulError
if path
contains an internal 0 byte. Returns
SpineError::PathNotUtf8
if the specified path is not utf-8.
sourcepub fn scale(&self) -> f32
pub fn scale(&self) -> f32
Scales bone positions, image sizes, and translations as they are loaded. This allows different size images to be used at runtime than were used in Spine.
See Scaling
in the
Spine Runtimes Guide.
sourcepub const fn c_ptr(&self) -> *mut spSkeletonJson
pub const fn c_ptr(&self) -> *mut spSkeletonJson
Get a pointer to the underlying spine-c
type.