Class: RedBird::Camera
- Inherits:
-
Object
- Object
- RedBird::Camera
- Defined in:
- lib/red_bird/camera.rb
Overview
Because most of the time the tilemap used as the scenario is larger than the screen, you need to choose an entity to use as a reference. A Camera control the scenario offset and makes the position of the scene rendered in the screen be relative to an entity.
Instance Method Summary collapse
-
#call ⇒ Object
Updates scenario offset according to entity position.
-
#focus=(focus) ⇒ Object
Change the camere focus.
-
#initialize(focus, scenario) ⇒ Camera
constructor
A new instance of Camera.
Constructor Details
#initialize(focus, scenario) ⇒ Camera
Returns a new instance of Camera.
15 16 17 18 19 20 |
# File 'lib/red_bird/camera.rb', line 15 def initialize(focus, scenario) @scenario = scenario @max_hor_offset = @scenario.total_width - @scenario.width @max_ver_offset = @scenario.total_height - @scenario.height self.focus = focus end |
Instance Method Details
#call ⇒ Object
Updates scenario offset according to entity position.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/red_bird/camera.rb', line 34 def call hor_offset = (@focus.relative_pos_x - @hor_center).to_i if hor_offset < 0 then @scenario.hor_offset = 0 elsif hor_offset > @max_hor_offset then @scenario.hor_offset = @max_hor_offset else @scenario.hor_offset = hor_offset end ver_offset = (@focus.relative_pos_y - @ver_center).to_i if ver_offset < 0 then @scenario.ver_offset = 0 elsif ver_offset > @max_ver_offset then @scenario.ver_offset = @max_ver_offset else @scenario.ver_offset = ver_offset end end |
#focus=(focus) ⇒ Object
Change the camere focus.
26 27 28 29 |
# File 'lib/red_bird/camera.rb', line 26 def focus=(focus) @focus = focus set_center end |