Class: Kawaii::SceneManager

Inherits:
Object
  • Object
show all
Defined in:
lib/kawaii/scene_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scene = nil) ⇒ SceneManager

Returns a new instance of SceneManager.



5
6
7
8
9
10
11
# File 'lib/kawaii/scene_manager.rb', line 5

def initialize scene = nil
	@scene = scene
	@old_scene = nil
	@current_transition = 0.0
	@state = :none
	@state = :transition if @scene != nil
end

Instance Attribute Details

#sceneObject

Returns the value of attribute scene.



3
4
5
# File 'lib/kawaii/scene_manager.rb', line 3

def scene
  @scene
end

Instance Method Details

#drawObject



41
42
43
44
45
46
47
48
# File 'lib/kawaii/scene_manager.rb', line 41

def draw
	if @old_scene != nil
		@old_scene.draw
	end
	if @scene != nil
		@scene.draw
	end
end

#push_scene(scene) ⇒ Object



13
14
15
16
# File 'lib/kawaii/scene_manager.rb', line 13

def push_scene scene
	@old_scene = @scene
	@scene = scene		
end

#update(dt) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kawaii/scene_manager.rb', line 18

def update dt
	case @state
		when :none
		when :transition
			if @scene != nil
				@scene.transition_in @current_transition, SCENE_TRANSITION_DURATION
			end
			if @old_scene != nil
				@old_scene.transition_out @current_transition, SCENE_TRANSITION_DURATION
			end

			@current_transition += dt
			if @current_transition > SCENE_TRANSITION_DURATION
				@state = :transition_done
			end
		when :transition_done
			@current_transition = 0.0
			@old_scene = nil
			@state = :none
		else
	end
end