// rendering_system.rs
pub struct RenderingSystem<'a> {
//...
pub fn get_image(&mut self, renderable: &Renderable, delta: Duration) -> Image {
let path_index = match renderable.kind() {
RenderableKind::Static => {
// We only have one image, so we just return that
0
}
RenderableKind::Animated => {
// If we have multiple, we want to select the right one based on the delta time.
// First we get the delta in milliseconds, we % by 1000 to get the seconds only
// and finally we divide by 250 to get a number between 0 and 4. If it's 4
// we technically are on the next iteration of the loop (or on 0), but we will let
// the renderable handle this logic of wrapping frames.
((delta.as_millis() % 1000) / 250) as usize
}
};
let image_path = renderable.path(path_index);
Image::new(self.context, image_path).expect("expected image")
}
}
Hi, It should be impl Rendering system instead of pub struct when trying to do the animation.
I am talking about this function in the book: