Method: OR2D::Camera#initialize

Defined in:
lib/or2d/camera.rb

#initialize(viewport_width = OR2D.game.screen_width, viewport_height = OR2D.game.screen_height, target = OR2D::Entity.new(:square, { size: 1, x: 0, y: 0, show: false }), speed = 1) ⇒ Camera

Constructs a new Camera object.

Parameters:

  • viewport_width (Integer) (defaults to: OR2D.game.screen_width)

    the width of the viewport

  • viewport_height (Integer) (defaults to: OR2D.game.screen_height)

    the height of the viewport

  • target (OR2D::Entity) (defaults to: OR2D::Entity.new(:square, { size: 1, x: 0, y: 0, show: false }))

    the target of the camera

Since:

  • 2023-04-26



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/or2d/camera.rb', line 16

def initialize(viewport_width = OR2D.game.screen_width,
               viewport_height = OR2D.game.screen_height,
               target = OR2D::Entity.new(:square, { size: 1, x: 0, y: 0, show: false }),
               speed = 1)
  @target = target
  @speed = speed
  @viewport = OR2D::Entity.new(:rectangle, {
    x: (OR2D.game.screen_width / 2) - viewport_width,
    y: (OR2D.game.screen_height / 2) + viewport_height,
    width: viewport_width,
    height: viewport_height,
    show: false
  })
end