11use bevy:: {
22 app:: AppExit ,
3- core:: Time ,
4- input:: system:: exit_on_esc_system,
53 prelude:: {
6- debug, App , AssetServer , Color , Commands , Component , DefaultPlugins , Entity , EventReader ,
7- EventWriter , HorizontalAlign , OrthographicCameraBundle , ParallelSystemDescriptorCoercion ,
4+ debug, App , AssetServer , Camera2dBundle , Color , Commands , Component , DefaultPlugins ,
5+ Entity , EventReader , EventWriter , HorizontalAlign , ParallelSystemDescriptorCoercion ,
86 ParamSet , Query , Res , ResMut , SpriteBundle , Text as BevyText , Text2dBundle , TextAlignment ,
97 TextStyle , Transform , Vec2 , VerticalAlign , Windows ,
108 } ,
9+ render:: texture:: ImageSettings ,
10+ time:: Time ,
1111 utils:: HashMap ,
12+ window:: close_on_esc,
1213} ;
1314use bevy_prototype_lyon:: prelude:: * ;
1415use std:: {
@@ -209,18 +210,18 @@ pub fn add_texts(commands: &mut Commands, asset_server: &Res<AssetServer>, engin
209210 let text_string = text. value . clone ( ) ;
210211 let font_path = text. font . clone ( ) ;
211212 commands. spawn ( ) . insert ( text) . insert_bundle ( Text2dBundle {
212- text : BevyText :: with_section (
213+ text : BevyText :: from_section (
213214 text_string,
214215 TextStyle {
215216 font : asset_server. load ( font_path. as_str ( ) ) ,
216217 font_size,
217218 color : Color :: WHITE ,
218219 } ,
219- TextAlignment {
220- vertical : VerticalAlign :: Center ,
221- horizontal : HorizontalAlign :: Center ,
222- } ,
223- ) ,
220+ )
221+ . with_alignment ( TextAlignment {
222+ vertical : VerticalAlign :: Center ,
223+ horizontal : HorizontalAlign :: Center ,
224+ } ) ,
224225 transform,
225226 ..Default :: default ( )
226227 } ) ;
@@ -230,12 +231,13 @@ pub fn add_texts(commands: &mut Commands, asset_server: &Res<AssetServer>, engin
230231/// system - update current window dimensions in the engine, because people resize windows
231232#[ doc( hidden) ]
232233pub fn update_window_dimensions ( windows : Res < Windows > , mut engine : ResMut < Engine > ) {
233- // Unwrap: If we can't access the primary window...there's no point to running Rusty Engine
234- let window = windows. get_primary ( ) . unwrap ( ) ;
235- let screen_dimensions = Vec2 :: new ( window. width ( ) , window. height ( ) ) ;
236- if screen_dimensions != engine. window_dimensions {
237- engine. window_dimensions = screen_dimensions;
238- debug ! ( "Set window dimensions: {}" , engine. window_dimensions) ;
234+ // It's possible to not have window dimensions for the first frame or two
235+ if let Some ( window) = windows. get_primary ( ) {
236+ let screen_dimensions = Vec2 :: new ( window. width ( ) , window. height ( ) ) ;
237+ if screen_dimensions != engine. window_dimensions {
238+ engine. window_dimensions = screen_dimensions;
239+ debug ! ( "Set window dimensions: {}" , engine. window_dimensions) ;
240+ }
239241 }
240242}
241243
@@ -296,11 +298,12 @@ impl<S: Send + Sync + 'static> Game<S> {
296298 pub fn run ( & mut self , initial_game_state : S ) {
297299 self . app
298300 . insert_resource :: < WindowDescriptor > ( self . window_descriptor . clone ( ) )
301+ . insert_resource ( ImageSettings :: default_nearest ( ) )
299302 . insert_resource :: < S > ( initial_game_state) ;
300303 self . app
301304 // Built-ins
302305 . add_plugins ( DefaultPlugins )
303- . add_system ( exit_on_esc_system )
306+ . add_system ( close_on_esc )
304307 // External Plugins
305308 . add_plugin ( ShapePlugin ) // bevy_prototype_lyon, for displaying sprite colliders
306309 // Rusty Engine Plugins
@@ -319,7 +322,7 @@ impl<S: Send + Sync + 'static> Game<S> {
319322 self . app
320323 . world
321324 . spawn ( )
322- . insert_bundle ( OrthographicCameraBundle :: new_2d ( ) ) ;
325+ . insert_bundle ( Camera2dBundle :: default ( ) ) ;
323326 let engine = std:: mem:: take ( & mut self . engine ) ;
324327 self . app . insert_resource ( engine) ;
325328 let logic_functions = std:: mem:: take ( & mut self . logic_functions ) ;
0 commit comments