Class: Camera
- Inherits:
-
Object
- Object
- Camera
- Defined in:
- lib/fantasy/camera.rb
Overview
Represents Coordinates of the camera and it affects the screen position of all Actors and Backgrounds.
There is only one active Camera and it is acceded by Camera.main. This Camera is initialized automatically
and it is already accessible. It can also be changed by another Camera instance.`
Class Attribute Summary collapse
-
.main ⇒ Camera
The active Camera.
Instance Attribute Summary collapse
-
#direction ⇒ Coordinates
Controls the direction in which the Camera will move in the next frame.
-
#position ⇒ Coordinates
Coordinates object where x and y represent the position of the Camera in the World (no necessarily in the Screen).
-
#speed ⇒ Float
Controls the pixels per second which the Camera will move in the next frame.
Instance Method Summary collapse
-
#initialize(position: Coordinates.zero) ⇒ Camera
constructor
Generates a Camera with all the default attribute values.
-
#on_after_move(&block) ⇒ Object
Triggered on every frame after the move has been executed.
Constructor Details
#initialize(position: Coordinates.zero) ⇒ Camera
Generates a Camera with all the default attribute values
74 75 76 77 78 79 |
# File 'lib/fantasy/camera.rb', line 74 def initialize(position: Coordinates.zero) @position = position @direction = Coordinates.zero @speed = 0 @on_after_move_callback = nil end |
Class Attribute Details
.main ⇒ Camera
Returns The active Camera.
103 104 105 |
# File 'lib/fantasy/camera.rb', line 103 def main @main end |
Instance Attribute Details
#direction ⇒ Coordinates
The the pixels per second is represented by the @speed attribute
Controls the direction in which the Camera will move in the next frame.
Default Coordinates.zero.
51 52 53 |
# File 'lib/fantasy/camera.rb', line 51 def direction @direction end |
#position ⇒ Coordinates
Coordinates object where x and y represent the position of the Camera in the World (no necessarily in the Screen).
Default Coordinates.zero.
39 40 41 |
# File 'lib/fantasy/camera.rb', line 39 def position @position end |
#speed ⇒ Float
The the direction is represented by the @direction attribute
Controls the pixels per second which the Camera will move in the next frame.
Default 0.
63 64 65 |
# File 'lib/fantasy/camera.rb', line 63 def speed @speed end |
Instance Method Details
#on_after_move(&block) ⇒ Object
Triggered on every frame after the move has been executed
97 98 99 |
# File 'lib/fantasy/camera.rb', line 97 def on_after_move(&block) @on_after_move_callback = block end |