root/lang/ruby/starframe/lib/starframe/scene.rb @ 27902

Revision 27902, 1.3 kB (checked in by isaisstillalive, 4 years ago)
  • Renderableモジュールを作成し、SceneをRenderable化
Line 
1# = StarFrame::Scene -- シーン
2
3require "starframe/eventable"
4require "starframe/initializable"
5require "starframe/updatable"
6require "starframe/renderable"
7
8module StarFrame
9  # = Sceneクラス
10  # シーンクラス。
11  class Scene
12    include Eventable
13    include Initializable
14    include Updatable
15    include Renderable
16   
17    # StarRuby::Game.run内で呼ぶこと
18    # StarRuby::Game.run外で呼びたい場合はScene.to_procを使うこと
19    def initialize game, *args
20      @game   = game
21      @screen = game.screen
22      @running = true
23     
24      init *args
25    end
26   
27    def call
28      catch :exit_scene do
29        update
30       
31        @screen.clear
32        call_render
33       
34        true
35      end
36    end
37   
38    def start
39      catch :exit_scene do
40        loop do
41          if @game.window_closing?
42            quit
43            return nil
44          end
45         
46          @game.wait
47          @game.update_state
48          return @next_scene unless call
49          @game.update_screen
50        end
51      end
52    end
53   
54    private
55    def exit_scene
56      quit
57      @next_scene = nil
58      throw :exit_scene, false
59    end
60   
61    def next_scene next_scene
62      quit
63      @next_scene = next_scene
64      throw :exit_scene, false
65    end
66  end
67end
Note: See TracBrowser for help on using the browser.