Class: Camera2D
- Inherits:
-
Object
- Object
- Camera2D
- Defined in:
- src/ruby/models/camera2d.rb,
mrb_doc/models/camera2d.rb
Overview
Camera2D is used for simply moving a viewport around.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#as_in_viewport(vector) ⇒ Vector2
Pass in a vector with world coordinates to see what that translates to in the camera’s viewport.
-
#as_in_world(vector) ⇒ Vector2
Pass in a vector with camera viewport coordinates to see what that translates to in the world.
-
#drawing { ... } ⇒ nil
Draws the world through the lens of the camera.
-
#initialize(offset, target, rotation, zoom) ⇒ Camera2D
constructor
Creates a new instance of Camera2D.
-
#to_h ⇒ Hash
Return the object represented by a Hash.
Constructor Details
Instance Attribute Details
#rotation ⇒ Float
7 8 9 |
# File 'src/ruby/models/camera2d.rb', line 7 def rotation @rotation end |
#zoom ⇒ Float
7 8 9 |
# File 'src/ruby/models/camera2d.rb', line 7 def zoom @zoom end |
Instance Method Details
#as_in_viewport(vector) ⇒ Vector2
Pass in a vector with world coordinates to see what that translates to in the camera’s viewport.
52 53 54 |
# File 'src/ruby/models/camera2d.rb', line 52 def (vector) get_world_to_screen2D(vector, self) end |
#as_in_world(vector) ⇒ Vector2
Pass in a vector with camera viewport coordinates to see what that translates to in the world.
60 61 62 |
# File 'src/ruby/models/camera2d.rb', line 60 def as_in_world(vector) get_screen_to_world2D(vector, self) end |
#drawing { ... } ⇒ nil
Draws the world through the lens of the camera
41 42 43 44 45 46 |
# File 'src/ruby/models/camera2d.rb', line 41 def drawing(&block) begin_mode2D(self) block.call ensure end_mode2D end |
#to_h ⇒ Hash
Return the object represented by a Hash
29 30 31 32 33 34 35 36 |
# File 'src/ruby/models/camera2d.rb', line 29 def to_h { offset: offset.to_h, target: target.to_h, rotation: rotation, zoom: zoom, } end |