indexing description: "[ Main scene of never ending background example ]" date: "$Date$" revision: "$Revision$" class NEVER_ENDING_BACKGROUND_SCENE inherit EM_DRAWABLE_SCENE redefine initialize_scene, handle_key_down_event end EM_SHARED_BITMAP_FACTORY create make feature -- Initialization make(a_screen: EM_VIDEO_SURFACE) is -- calls all init functions do screen := a_screen make_scene end feature {NONE} -- intern Initialization initialize_scene is -- Create objects the scene is constructed of and put them into `scene'. local background_viewport: EM_ZOOMABLE_CONTAINER do -- Create viewport for only showing part of the background. create background_viewport.make (screen.width - 200, screen.height - 200) background_viewport.set_x_y (100, 100) main_container.extend (background_viewport) -- Create endless background inside viewport. bitmap_factory.create_bitmap_from_image ("back1.gif") create endless_background_horizontal.make (bitmap_factory.last_bitmap) start_animating (endless_background_horizontal) create endless_background_vertical.make (endless_background_horizontal) start_animating (endless_background_vertical) endless_background_vertical.set_x_y (-100, -100) background_viewport.extend (endless_background_vertical) -- Create endless text in front of background. create endless_text_horizontal.make (create {DEMO_TEXT}.make) start_animating (endless_text_horizontal) create endless_text_vertical.make (endless_text_horizontal) start_animating (endless_text_vertical) main_container.extend (endless_text_vertical) -- Subscribe event handlers event_loop.key_down_event.subscribe (agent handle_key_down_event (?)) end feature {NONE} -- Keyboard management handle_key_down_event (a_keyboard_event: EM_KEYBOARD_EVENT) is -- Handle keyboard events. require else a_keyboard_event_not_void: a_keyboard_event /= Void local vspeed_diff: INTEGER hspeed_diff: INTEGER do if a_keyboard_event.key = a_keyboard_event.sdlk_escape then quit end if a_keyboard_event.key = a_keyboard_event.sdlk_up then vspeed_diff := 5 end if a_keyboard_event.key = a_keyboard_event.sdlk_down then vspeed_diff := -5 end if a_keyboard_event.key = a_keyboard_event.sdlk_left then hspeed_diff := 5 end if a_keyboard_event.key = a_keyboard_event.sdlk_right then hspeed_diff := -5 end endless_text_vertical.set_speed (endless_text_vertical.speed + vspeed_diff) endless_background_vertical.set_speed (endless_background_vertical.speed + 2 * vspeed_diff) endless_text_horizontal.set_speed (endless_text_horizontal.speed + hspeed_diff) endless_background_horizontal.set_speed (endless_background_horizontal.speed + 2 * hspeed_diff) end feature {NONE} -- Implementation -- first_scene: EM_DRAWABLE_SCENE -- -- The scene used to run the never ending backgrounds in. endless_text_horizontal: EM_NEVER_ENDING_BACKGROUND_HORIZONTAL -- The horizontal background for the demo text endless_text_vertical: EM_NEVER_ENDING_BACKGROUND_VERTICAL -- The vertical background for the demo text endless_background_horizontal: EM_NEVER_ENDING_BACKGROUND_HORIZONTAL -- The horizontal background for the back image endless_background_vertical: EM_NEVER_ENDING_BACKGROUND_VERTICAL -- The vertical background for the back image end