i created a struct clock and then i implement a draw function as such :
fn draw(&mut self, e: &Event, window: &mut PistonWindow) {
window.draw_2d(e, |c, g, _| {...}); //draw a circle and a rotating line
}
in main i have the following :
let mut app = clock::new();
let mut app2 = clock::new();
app2.x += 200.0; //translate seconde clock
let mut now = Instant::now();
while let Some(e) = window.next() {
app.draw(&e, &mut window);
app.update(now.elapsed().as_millis());
app2.draw(&e, &mut window);
app2.update(now.elapsed().as_millis());
now = Instant::now();
}
I don't know why only one clock is drawn (I'm on mobile now, so I can't test).
But I noticed that you get a new value for now each time in the end of the loop. I would recommend to always work with an initial time stamp.
As it is now, the two clocks will diverge (the first one will run slower than the second one), as it requests the elapsed time earlier in the loop.
thank you,
i corrected the timer (fun fact : the angular speed isn't constant anymore).
Still working on drawing 2 time the same struct, i try defining a second struc for the second clock, it doesn't work. I tried using the opengl backend directly and the viewport to draw instead of window.draw_2d. Also doesn't work.
I don't understand the concept of piston where am i drawing ? , the documentation isn't really helpful.