use std::time::Duration;
use ggez::{
graphics::{Color, DrawParam, Drawable, Text},
Context,
};
pub struct BScene {
duration: Duration,
hello: Text,
}
impl BScene {
pub fn new(_ctx: &Context) -> Self {
Self {
duration: Duration::from_secs(2),
hello: Text::new("This scene will close itself after 2 seconds."),
}
}
}
impl mooeye::scene_manager::Scene for BScene {
fn update(
&mut self,
ctx: &mut ggez::Context,
) -> Result<mooeye::scene_manager::SceneSwitch, ggez::GameError> {
self.duration = self.duration.saturating_sub(ctx.time.delta());
if self.duration.is_zero() {
return Ok(mooeye::scene_manager::SceneSwitch::Pop(1));
}
Ok(mooeye::scene_manager::SceneSwitch::None)
}
fn draw(
&mut self,
ctx: &mut ggez::Context,
_mouse_listen: bool,
) -> Result<(), ggez::GameError> {
let mut canvas = ggez::graphics::Canvas::from_frame(ctx, Color::from_rgb(100, 100, 150));
canvas.set_sampler(ggez::graphics::Sampler::nearest_clamp());
self.hello.draw(&mut canvas, DrawParam::default());
canvas.finish(ctx)?;
Ok(())
}
}