comparison src/th06/anm0_vm.rs @ 656:988e5130fb00

Add a simpler Sprite::new() which doesn’t override width/height.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 09 Aug 2019 01:03:43 +0200
parents 3331eb7389b3
children 3a9d82a02c88
comparison
equal deleted inserted replaced
655:6b4d2b405442 656:988e5130fb00
61 color: [u8; 4], 61 color: [u8; 4],
62 } 62 }
63 63
64 impl Sprite { 64 impl Sprite {
65 /// Create a new sprite. 65 /// Create a new sprite.
66 pub fn new(width_override: f32, height_override: f32) -> Sprite { 66 pub fn new() -> Sprite {
67 Sprite {
68 changed: true,
69 visible: true,
70 rescale: [1., 1.],
71 color: [255, 255, 255, 255],
72 ..Default::default()
73 }
74 }
75
76 /// Create a new sprite overriding its size.
77 pub fn with_size(width_override: f32, height_override: f32) -> Sprite {
67 Sprite { 78 Sprite {
68 width_override, 79 width_override,
69 height_override, 80 height_override,
70 changed: true, 81 changed: true,
71 visible: true, 82 visible: true,
427 let mut buf = vec![]; 438 let mut buf = vec![];
428 file.read_to_end(&mut buf).unwrap(); 439 file.read_to_end(&mut buf).unwrap();
429 let anm0 = Anm0::from_slice(&buf).unwrap(); 440 let anm0 = Anm0::from_slice(&buf).unwrap();
430 assert_eq!(anm0.size, (256, 256)); 441 assert_eq!(anm0.size, (256, 256));
431 assert_eq!(anm0.format, 5); 442 assert_eq!(anm0.format, 5);
432 let sprite = Rc::new(RefCell::new(Sprite::new(0., 0.))); 443 let sprite = Rc::new(RefCell::new(Sprite::new()));
433 let prng = Rc::new(RefCell::new(Prng::new(0))); 444 let prng = Rc::new(RefCell::new(Prng::new(0)));
434 let mut anm_runner = AnmRunner::new(&anm0, 1, sprite.clone(), Rc::downgrade(&prng), 0); 445 let mut anm_runner = AnmRunner::new(&anm0, 1, sprite.clone(), Rc::downgrade(&prng), 0);
435 for _ in 0..50 { 446 for _ in 0..50 {
436 anm_runner.run_frame(); 447 anm_runner.run_frame();
437 } 448 }