pub struct Engine { /* private fields */ }Expand description
The thing that makes the computer go
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn is_key_down(&self, key: Key) -> bool
pub fn is_key_down(&self, key: Key) -> bool
Checks if a key is down
Examples found in repository?
110 fn update(&mut self, engine_handle: &mut Engine) {
111 let dt = engine_handle.get_frame_delta_time();
112 self.pos.x += 100.0 * dt;
113 if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
114 let new_texture = Texture::new(
115 engine_handle,
116 "examples/eggshark.png",
117 LoadingOp::Background,
118 );
119 self.texture_material.change_texture(new_texture);
120 }
121
122 self.state = engine_handle.is_key_down(Key::Space);
123 }More examples
66 fn update(&mut self, engine_handle: &mut Engine) {
67 let dt = engine_handle.get_frame_delta_time();
68 let mouse_pos = engine_handle.get_mouse_position();
69 let size = engine_handle.get_window_size();
70
71 let move_factor = 15.0;
72
73 if engine_handle.is_key_down(Key::A) {
74 self.camera.center.x -= move_factor * dt;
75 }
76
77 if engine_handle.is_key_down(Key::D) {
78 self.camera.center.x += move_factor * dt;
79 }
80
81 if engine_handle.is_key_down(Key::W) {
82 self.camera.center.y += move_factor * dt;
83 }
84
85 if engine_handle.is_key_down(Key::S) {
86 self.camera.center.y -= move_factor * dt;
87 }
88
89 if engine_handle.is_key_down(Key::Left) {
90 self.camera.rotation += move_factor * dt;
91 }
92
93 if engine_handle.is_key_down(Key::Right) {
94 self.camera.rotation -= move_factor * dt;
95 }
96
97 if engine_handle.is_key_down(Key::L) {
98 self.camera.scale += vec2!(2.0 * dt, 2.0 * dt);
99 }
100
101 if engine_handle.is_key_down(Key::K) {
102 self.camera.scale -= vec2!(2.0 * dt, 2.0 * dt);
103 }
104
105 if engine_handle.is_key_pressed(Key::Enter) {
106 self.camera.rotation += 45.0;
107 }
108
109 let trans_mouse = self.camera.transform_point(mouse_pos, size);
110
111 self.text.set_text(
112 &format!(
113 "Screen mouse pos: {:.3}, {:.3}\nWorld mouse pos: {:.3}, {:.3}",
114 mouse_pos.x, mouse_pos.y, trans_mouse.x, trans_mouse.y
115 ),
116 Colour::WHITE,
117 engine_handle,
118 );
119
120 self.text.prepare(engine_handle);
121 }Sourcepub fn is_key_pressed(&self, key: Key) -> bool
pub fn is_key_pressed(&self, key: Key) -> bool
Only returns true on the frame where the key is first pressed down
Examples found in repository?
66 fn update(&mut self, engine_handle: &mut Engine) {
67 let dt = engine_handle.get_frame_delta_time();
68 let mouse_pos = engine_handle.get_mouse_position();
69 let size = engine_handle.get_window_size();
70
71 let move_factor = 15.0;
72
73 if engine_handle.is_key_down(Key::A) {
74 self.camera.center.x -= move_factor * dt;
75 }
76
77 if engine_handle.is_key_down(Key::D) {
78 self.camera.center.x += move_factor * dt;
79 }
80
81 if engine_handle.is_key_down(Key::W) {
82 self.camera.center.y += move_factor * dt;
83 }
84
85 if engine_handle.is_key_down(Key::S) {
86 self.camera.center.y -= move_factor * dt;
87 }
88
89 if engine_handle.is_key_down(Key::Left) {
90 self.camera.rotation += move_factor * dt;
91 }
92
93 if engine_handle.is_key_down(Key::Right) {
94 self.camera.rotation -= move_factor * dt;
95 }
96
97 if engine_handle.is_key_down(Key::L) {
98 self.camera.scale += vec2!(2.0 * dt, 2.0 * dt);
99 }
100
101 if engine_handle.is_key_down(Key::K) {
102 self.camera.scale -= vec2!(2.0 * dt, 2.0 * dt);
103 }
104
105 if engine_handle.is_key_pressed(Key::Enter) {
106 self.camera.rotation += 45.0;
107 }
108
109 let trans_mouse = self.camera.transform_point(mouse_pos, size);
110
111 self.text.set_text(
112 &format!(
113 "Screen mouse pos: {:.3}, {:.3}\nWorld mouse pos: {:.3}, {:.3}",
114 mouse_pos.x, mouse_pos.y, trans_mouse.x, trans_mouse.y
115 ),
116 Colour::WHITE,
117 engine_handle,
118 );
119
120 self.text.prepare(engine_handle);
121 }Sourcepub fn is_key_released(&self, key: Key) -> bool
pub fn is_key_released(&self, key: Key) -> bool
Only returns true on the frame where the key first returns back up
Sourcepub fn check_modifiers(&self, modifer: ModifierKeys) -> bool
pub fn check_modifiers(&self, modifer: ModifierKeys) -> bool
This will tell you if certain keys like CTRL or Shift are modifying the current key presses.
Sourcepub fn get_current_text(&self) -> Option<&str>
pub fn get_current_text(&self) -> Option<&str>
returns the text vule of any keys held down helpfull for text
entry. As if Shift + w is held this will return Some("W")
Sourcepub fn is_mouse_key_down(&self, key: MouseKey) -> bool
pub fn is_mouse_key_down(&self, key: MouseKey) -> bool
Checks if a mouse key is down
Sourcepub fn is_mouse_key_up(&self, key: MouseKey) -> bool
pub fn is_mouse_key_up(&self, key: MouseKey) -> bool
Checks if a mouse key is up
Sourcepub fn is_mouse_key_pressed(&self, key: MouseKey) -> bool
pub fn is_mouse_key_pressed(&self, key: MouseKey) -> bool
Only returns true on the frame where the key is first pressed down
Examples found in repository?
More examples
110 fn update(&mut self, engine_handle: &mut Engine) {
111 let dt = engine_handle.get_frame_delta_time();
112 self.pos.x += 100.0 * dt;
113 if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
114 let new_texture = Texture::new(
115 engine_handle,
116 "examples/eggshark.png",
117 LoadingOp::Background,
118 );
119 self.texture_material.change_texture(new_texture);
120 }
121
122 self.state = engine_handle.is_key_down(Key::Space);
123 }48 fn update(&mut self, engine_handle: &mut Engine) {
49 self.font_size += 2.0 * engine_handle.get_frame_delta_time();
50
51 self.text_mat.set_font_size(self.font_size, engine_handle);
52 self.text_mat
53 .set_line_height(self.font_size * 1.3, engine_handle);
54
55 if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
56 self.text_mat.set_text_with_font(
57 "hello I am talking to you here???",
58 Colour::GREEN,
59 &self.comic,
60 engine_handle,
61 );
62 }
63
64 self.text_mat.prepare(engine_handle);
65 }Sourcepub fn is_mouse_key_released(&self, key: MouseKey) -> bool
pub fn is_mouse_key_released(&self, key: MouseKey) -> bool
Only returns true on the frame where the key first returns back up
Sourcepub fn get_mouse_position(&self) -> Vec2<f32>
pub fn get_mouse_position(&self) -> Vec2<f32>
Gives the current position of the mouse in physical pixels
Examples found in repository?
95 fn update(&mut self, engine_handle: &mut Engine) {
96 let mouse_pos = engine_handle.get_mouse_position();
97 self.mouse_pos = mouse_pos;
98 let window_size = engine_handle.get_window_size();
99
100 self.light.pos_x = mouse_pos.x / window_size.x as f32;
101 self.light.pos_y = mouse_pos.y / window_size.y as f32;
102 self.material
103 .update_uniform_data(&self.light, &engine_handle)
104 .unwrap();
105
106 self.material
107 .update_uniform_texture(&mut self.uniform_texture, engine_handle)
108 .unwrap_or_else(|_| {});
109 }More examples
108 fn update(&mut self, engine_handle: &mut Engine) {
109 let dt = engine_handle.get_frame_delta_time();
110
111 self.theta.x = (self.theta.x + dt) % (2.0 * PI);
112
113 let size = engine_handle.get_window_size();
114 let mouse_pos = engine_handle.get_mouse_position();
115
116 let new_data = MousePos {
117 x: mouse_pos.x / size.x as f32,
118 y: mouse_pos.y / size.y as f32,
119 _junk: 0.0,
120 _padding2: 0.0,
121 };
122
123 self.data = new_data;
124 self.mouse_material
125 .update_uniform_data(&self.data, &engine_handle)
126 .unwrap();
127 self.circle_material
128 .update_uniform_data(&self.theta, &engine_handle)
129 .unwrap();
130 }66 fn update(&mut self, engine_handle: &mut Engine) {
67 let dt = engine_handle.get_frame_delta_time();
68 let mouse_pos = engine_handle.get_mouse_position();
69 let size = engine_handle.get_window_size();
70
71 let move_factor = 15.0;
72
73 if engine_handle.is_key_down(Key::A) {
74 self.camera.center.x -= move_factor * dt;
75 }
76
77 if engine_handle.is_key_down(Key::D) {
78 self.camera.center.x += move_factor * dt;
79 }
80
81 if engine_handle.is_key_down(Key::W) {
82 self.camera.center.y += move_factor * dt;
83 }
84
85 if engine_handle.is_key_down(Key::S) {
86 self.camera.center.y -= move_factor * dt;
87 }
88
89 if engine_handle.is_key_down(Key::Left) {
90 self.camera.rotation += move_factor * dt;
91 }
92
93 if engine_handle.is_key_down(Key::Right) {
94 self.camera.rotation -= move_factor * dt;
95 }
96
97 if engine_handle.is_key_down(Key::L) {
98 self.camera.scale += vec2!(2.0 * dt, 2.0 * dt);
99 }
100
101 if engine_handle.is_key_down(Key::K) {
102 self.camera.scale -= vec2!(2.0 * dt, 2.0 * dt);
103 }
104
105 if engine_handle.is_key_pressed(Key::Enter) {
106 self.camera.rotation += 45.0;
107 }
108
109 let trans_mouse = self.camera.transform_point(mouse_pos, size);
110
111 self.text.set_text(
112 &format!(
113 "Screen mouse pos: {:.3}, {:.3}\nWorld mouse pos: {:.3}, {:.3}",
114 mouse_pos.x, mouse_pos.y, trans_mouse.x, trans_mouse.y
115 ),
116 Colour::WHITE,
117 engine_handle,
118 );
119
120 self.text.prepare(engine_handle);
121 }Sourcepub fn get_mouse_delta(&self) -> Vec2<f32>
pub fn get_mouse_delta(&self) -> Vec2<f32>
Returns how much the mouse has moved in the last frame
Sourcepub fn window_has_focus(&self) -> bool
pub fn window_has_focus(&self) -> bool
Sourcepub fn is_window_maximized(&self) -> bool
pub fn is_window_maximized(&self) -> bool
Sourcepub fn is_window_minimized(&self) -> bool
pub fn is_window_minimized(&self) -> bool
Sourcepub fn is_window_fullscreen(&self) -> bool
pub fn is_window_fullscreen(&self) -> bool
Sourcepub fn maximize_window(&self)
pub fn maximize_window(&self)
Sourcepub fn minimize_window(&self)
pub fn minimize_window(&self)
Sourcepub fn set_window_icon(&self, path: &str) -> Result<(), IconError>
pub fn set_window_icon(&self, path: &str) -> Result<(), IconError>
Will attempt to set the window icon for more details check the winit docs
§Panics
When called outside of the functions in the Game trait
Sourcepub fn set_window_title(&self, title: &str)
pub fn set_window_title(&self, title: &str)
Sourcepub fn set_window_position(&self, x: f32, y: f32)
pub fn set_window_position(&self, x: f32, y: f32)
Sourcepub fn set_window_min_size(&self, width: f32, height: f32)
pub fn set_window_min_size(&self, width: f32, height: f32)
Sourcepub fn get_window_position(&self) -> Option<Vec2<i32>>
pub fn get_window_position(&self) -> Option<Vec2<i32>>
Sourcepub fn get_window_size(&self) -> Vec2<u32>
pub fn get_window_size(&self) -> Vec2<u32>
Gets the phyisical size of the window,
Examples found in repository?
108 fn update(&mut self, engine_handle: &mut Engine) {
109 let dt = engine_handle.get_frame_delta_time();
110
111 self.theta.x = (self.theta.x + dt) % (2.0 * PI);
112
113 let size = engine_handle.get_window_size();
114 let mouse_pos = engine_handle.get_mouse_position();
115
116 let new_data = MousePos {
117 x: mouse_pos.x / size.x as f32,
118 y: mouse_pos.y / size.y as f32,
119 _junk: 0.0,
120 _padding2: 0.0,
121 };
122
123 self.data = new_data;
124 self.mouse_material
125 .update_uniform_data(&self.data, &engine_handle)
126 .unwrap();
127 self.circle_material
128 .update_uniform_data(&self.theta, &engine_handle)
129 .unwrap();
130 }More examples
15fn main() {
16 let mut engine = EngineBuilder::new()
17 .set_window_title("Lightmap")
18 .with_resolution((800, 800))
19 .build()
20 .unwrap();
21
22 let uniform_texture = UniformTexture::new(&engine, engine.get_window_size());
23
24 let light = Light {
25 colour: Colour::ORANGE,
26 pos_x: 0.0,
27 pos_y: 0.0,
28 brightness: 0.75,
29 aspect_ratio: 1.0,
30 };
31
32 let light_data = UniformData::new(&light);
33
34 let shader_options = ShaderOptions::with_all(&light_data, &uniform_texture);
35 let light_shader = Shader::new(
36 "examples/light.wgsl",
37 shader_options,
38 &mut engine,
39 LoadingOp::Blocking,
40 );
41
42 let material = MaterialBuilder::new()
43 .set_shader(light_shader)
44 .build(&mut engine);
45
46 let ocluder_material = MaterialBuilder::new().build(&mut engine);
47
48 let rectangles = vec![
49 Rectangle::new(Vec2 { x: 120.0, y: 20.0 }, Vec2 { x: 50.0, y: 50.0 }),
50 Rectangle::new(Vec2 { x: 270.0, y: 70.0 }, Vec2 { x: 50.0, y: 50.0 }),
51 Rectangle::new(Vec2 { x: 130.0, y: 280.0 }, Vec2 { x: 50.0, y: 50.0 }),
52 Rectangle::new(Vec2 { x: 220.0, y: 300.0 }, Vec2 { x: 50.0, y: 50.0 }),
53 Rectangle::new(Vec2 { x: 350.0, y: 350.0 }, Vec2 { x: 100.0, y: 100.0 }),
54 ];
55
56 let s = TextureExample {
57 material,
58 ocluder_material,
59 light,
60 uniform_texture,
61 rectangles,
62 mouse_pos: ZEROS,
63 };
64
65 engine.run(s);
66}
67
68struct TextureExample {
69 material: Material<Light>,
70 ocluder_material: Material,
71 light: Light,
72 uniform_texture: UniformTexture,
73 rectangles: Vec<Rectangle>,
74 mouse_pos: Vec2<f32>,
75}
76
77const ZEROS: Vec2<f32> = Vec2 { x: 0.0, y: 0.0 };
78
79impl Game for TextureExample {
80 fn render<'o>(&'o mut self, mut render_handle: RenderHandle<'o>) {
81 self.create_shadow_map(&mut render_handle);
82
83 let mut p2 = render_handle.begin_pass(Colour::BLACK);
84 let size = p2.get_size();
85 let size = Vec2 {
86 x: size.x as f32,
87 y: size.y as f32,
88 };
89
90 self.material
91 .add_rectangle(Vec2 { x: 0.0, y: 0.0 }, size, Colour::WHITE, &p2);
92 self.material.draw(&mut p2);
93 }
94
95 fn update(&mut self, engine_handle: &mut Engine) {
96 let mouse_pos = engine_handle.get_mouse_position();
97 self.mouse_pos = mouse_pos;
98 let window_size = engine_handle.get_window_size();
99
100 self.light.pos_x = mouse_pos.x / window_size.x as f32;
101 self.light.pos_y = mouse_pos.y / window_size.y as f32;
102 self.material
103 .update_uniform_data(&self.light, &engine_handle)
104 .unwrap();
105
106 self.material
107 .update_uniform_texture(&mut self.uniform_texture, engine_handle)
108 .unwrap_or_else(|_| {});
109 }66 fn update(&mut self, engine_handle: &mut Engine) {
67 let dt = engine_handle.get_frame_delta_time();
68 let mouse_pos = engine_handle.get_mouse_position();
69 let size = engine_handle.get_window_size();
70
71 let move_factor = 15.0;
72
73 if engine_handle.is_key_down(Key::A) {
74 self.camera.center.x -= move_factor * dt;
75 }
76
77 if engine_handle.is_key_down(Key::D) {
78 self.camera.center.x += move_factor * dt;
79 }
80
81 if engine_handle.is_key_down(Key::W) {
82 self.camera.center.y += move_factor * dt;
83 }
84
85 if engine_handle.is_key_down(Key::S) {
86 self.camera.center.y -= move_factor * dt;
87 }
88
89 if engine_handle.is_key_down(Key::Left) {
90 self.camera.rotation += move_factor * dt;
91 }
92
93 if engine_handle.is_key_down(Key::Right) {
94 self.camera.rotation -= move_factor * dt;
95 }
96
97 if engine_handle.is_key_down(Key::L) {
98 self.camera.scale += vec2!(2.0 * dt, 2.0 * dt);
99 }
100
101 if engine_handle.is_key_down(Key::K) {
102 self.camera.scale -= vec2!(2.0 * dt, 2.0 * dt);
103 }
104
105 if engine_handle.is_key_pressed(Key::Enter) {
106 self.camera.rotation += 45.0;
107 }
108
109 let trans_mouse = self.camera.transform_point(mouse_pos, size);
110
111 self.text.set_text(
112 &format!(
113 "Screen mouse pos: {:.3}, {:.3}\nWorld mouse pos: {:.3}, {:.3}",
114 mouse_pos.x, mouse_pos.y, trans_mouse.x, trans_mouse.y
115 ),
116 Colour::WHITE,
117 engine_handle,
118 );
119
120 self.text.prepare(engine_handle);
121 }Sourcepub fn get_window_scale_factor(&self) -> f64
pub fn get_window_scale_factor(&self) -> f64
Sourcepub fn toggle_fullscreen(&self)
pub fn toggle_fullscreen(&self)
Toggels fullscreen mode may fail on certain Operating Systems check the winit docs for more information
§Panics
When called outside of the functions in the Game trait
Sourcepub fn hide_cursor(&mut self)
pub fn hide_cursor(&mut self)
Sourcepub fn show_cursor(&mut self)
pub fn show_cursor(&mut self)
Sourcepub fn get_frame_delta_time(&self) -> f32
pub fn get_frame_delta_time(&self) -> f32
Gets the time since the previous frame or change in time between now and last frame
Examples found in repository?
More examples
110 fn update(&mut self, engine_handle: &mut Engine) {
111 let dt = engine_handle.get_frame_delta_time();
112 self.pos.x += 100.0 * dt;
113 if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
114 let new_texture = Texture::new(
115 engine_handle,
116 "examples/eggshark.png",
117 LoadingOp::Background,
118 );
119 self.texture_material.change_texture(new_texture);
120 }
121
122 self.state = engine_handle.is_key_down(Key::Space);
123 }48 fn update(&mut self, engine_handle: &mut Engine) {
49 self.font_size += 2.0 * engine_handle.get_frame_delta_time();
50
51 self.text_mat.set_font_size(self.font_size, engine_handle);
52 self.text_mat
53 .set_line_height(self.font_size * 1.3, engine_handle);
54
55 if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
56 self.text_mat.set_text_with_font(
57 "hello I am talking to you here???",
58 Colour::GREEN,
59 &self.comic,
60 engine_handle,
61 );
62 }
63
64 self.text_mat.prepare(engine_handle);
65 }108 fn update(&mut self, engine_handle: &mut Engine) {
109 let dt = engine_handle.get_frame_delta_time();
110
111 self.theta.x = (self.theta.x + dt) % (2.0 * PI);
112
113 let size = engine_handle.get_window_size();
114 let mouse_pos = engine_handle.get_mouse_position();
115
116 let new_data = MousePos {
117 x: mouse_pos.x / size.x as f32,
118 y: mouse_pos.y / size.y as f32,
119 _junk: 0.0,
120 _padding2: 0.0,
121 };
122
123 self.data = new_data;
124 self.mouse_material
125 .update_uniform_data(&self.data, &engine_handle)
126 .unwrap();
127 self.circle_material
128 .update_uniform_data(&self.theta, &engine_handle)
129 .unwrap();
130 }66 fn update(&mut self, engine_handle: &mut Engine) {
67 let dt = engine_handle.get_frame_delta_time();
68 let mouse_pos = engine_handle.get_mouse_position();
69 let size = engine_handle.get_window_size();
70
71 let move_factor = 15.0;
72
73 if engine_handle.is_key_down(Key::A) {
74 self.camera.center.x -= move_factor * dt;
75 }
76
77 if engine_handle.is_key_down(Key::D) {
78 self.camera.center.x += move_factor * dt;
79 }
80
81 if engine_handle.is_key_down(Key::W) {
82 self.camera.center.y += move_factor * dt;
83 }
84
85 if engine_handle.is_key_down(Key::S) {
86 self.camera.center.y -= move_factor * dt;
87 }
88
89 if engine_handle.is_key_down(Key::Left) {
90 self.camera.rotation += move_factor * dt;
91 }
92
93 if engine_handle.is_key_down(Key::Right) {
94 self.camera.rotation -= move_factor * dt;
95 }
96
97 if engine_handle.is_key_down(Key::L) {
98 self.camera.scale += vec2!(2.0 * dt, 2.0 * dt);
99 }
100
101 if engine_handle.is_key_down(Key::K) {
102 self.camera.scale -= vec2!(2.0 * dt, 2.0 * dt);
103 }
104
105 if engine_handle.is_key_pressed(Key::Enter) {
106 self.camera.rotation += 45.0;
107 }
108
109 let trans_mouse = self.camera.transform_point(mouse_pos, size);
110
111 self.text.set_text(
112 &format!(
113 "Screen mouse pos: {:.3}, {:.3}\nWorld mouse pos: {:.3}, {:.3}",
114 mouse_pos.x, mouse_pos.y, trans_mouse.x, trans_mouse.y
115 ),
116 Colour::WHITE,
117 engine_handle,
118 );
119
120 self.text.prepare(engine_handle);
121 }Sourcepub fn get_stable_fps(&self) -> f32
pub fn get_stable_fps(&self) -> f32
Returns a moving average of the last two frame times
Sourcepub fn get_target_fps(&self) -> Option<u16>
pub fn get_target_fps(&self) -> Option<u16>
Gets the current target fps
Sourcepub fn remove_target_fps(&mut self)
pub fn remove_target_fps(&mut self)
Will uncap the framerate and cause the engine to redner and update as soon as the next frame is ready unless VSYNC is on then it will draw at the VYSNC rate, which is dependant on user hardware.
Sourcepub fn remove_vsync(&mut self)
pub fn remove_vsync(&mut self)
Will turn off vysnc if the platform suports it, using AutoNoVsync for more information check PresentMode::AutoNoVsync.
§Panics
When called outside of the functions in the Game trait
Sourcepub fn add_vsync(&mut self)
pub fn add_vsync(&mut self)
Will turn off vysnc if the platform suports it, using AutoVsync for more information check PresentMode::AutoVsync.
§Panics
When called outside of the functions in the Game trait
Sourcepub fn set_target_fps(&mut self, fps: u16)
pub fn set_target_fps(&mut self, fps: u16)
Sets a target fps cap. The thread will spin sleep using the spin_sleep crate untill the desired frame time is reached. If the frames are slower than the target no action is taken to “speed” up the rendering and updating
Sourcepub fn measure_string(
&mut self,
text: &str,
font_size: f32,
line_height: f32,
) -> Vec2<f32>
pub fn measure_string( &mut self, text: &str, font_size: f32, line_height: f32, ) -> Vec2<f32>
Measures string based on the default font. To measure a string with a custom font use TextMaterial::get_measurements()
§Panics
When called outside of the functions in the Game trait
Sourcepub fn create_resource<P: AsRef<Path>>(
&mut self,
path: P,
loading_op: LoadingOp,
) -> ResourceId<Vec<u8>>
pub fn create_resource<P: AsRef<Path>>( &mut self, path: P, loading_op: LoadingOp, ) -> ResourceId<Vec<u8>>
Loads in a byte vector resource, can be used to load arbitary files.
Sourcepub fn get_loading_resource_count(&self) -> usize
pub fn get_loading_resource_count(&self) -> usize
This returns the current number of resources that are loading
Sourcepub fn get_byte_resource(&self, id: ResourceId<Vec<u8>>) -> Option<&Vec<u8>>
pub fn get_byte_resource(&self, id: ResourceId<Vec<u8>>) -> Option<&Vec<u8>>
Attemps to fetch a byte resource.
Returns None if the resource isnt loaded yet.
Sourcepub fn run<T>(self, game: T)where
T: Game + 'static,
pub fn run<T>(self, game: T)where
T: Game + 'static,
Takes the struct that implements the Game trait and starts the winit event loop running the game
Examples found in repository?
More examples
9fn main() {
10 let mut engine = EngineBuilder::new()
11 .with_resolution((400, 400))
12 .build()
13 .unwrap();
14
15 let material = MaterialBuilder::new().build(&mut engine);
16
17 let pos = DebugTriangle { material };
18
19 engine.run(pos);
20}9fn main() {
10 let engine = EngineBuilder::new().build().unwrap();
11
12 let text_mat = TextMaterial::new("this is a test", Colour::RED, 20.0, 20.0 * 1.3);
13
14 let text_example = TextExample {
15 text_mat,
16 text: String::new(),
17 };
18
19 engine.run(text_example);
20}11fn main() {
12 let mut engine = EngineBuilder::new().build().unwrap();
13
14 let comic = Font::new("examples/Comic.ttf", &mut engine, LoadingOp::Blocking);
15 let text_mat = TextMaterial::new("this is a test", Colour::RED, 0.5, 0.5 * 1.3);
16
17 let text_example = TextExample {
18 text_mat,
19 comic,
20 font_size: 0.5,
21 };
22
23 engine.run(text_example);
24}12fn main() {
13 let mut engine = EngineBuilder::new().build().unwrap();
14
15 let texture = Texture::new(&mut engine, "examples/bplogo.png", LoadingOp::Blocking);
16
17 let texture_material = MaterialBuilder::new()
18 .add_texture(texture)
19 .build(&mut engine);
20 let regular_material = MaterialBuilder::new().build(&mut engine);
21
22 let pos = Position {
23 pos: vec2! { 0.0 },
24 regular_material,
25 texture_material,
26 state: false,
27 };
28
29 engine.run(pos);
30}13fn main() {
14 let mut engine = EngineBuilder::new().build().unwrap();
15
16 let texture = Texture::new(&mut engine, "examples/bplogo.png", LoadingOp::Blocking);
17
18 let material = MaterialBuilder::new()
19 .add_texture(texture)
20 .build(&mut engine);
21
22 let camera = Camera::default();
23
24 let text = TextMaterial::new(
25 "Mouse pos: 0,0 \n Mouse pos: 0, 0",
26 Colour::WHITE,
27 15.0,
28 20.0,
29 );
30
31 let game = CameraExample {
32 material,
33 text,
34 camera,
35 };
36
37 engine.run(game);
38}Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Engine
impl !RefUnwindSafe for Engine
impl !Send for Engine
impl !Sync for Engine
impl Unpin for Engine
impl !UnwindSafe for Engine
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more