Class: OR2D::Cameras::CenteredCamera

Inherits:
OR2D::Camera show all
Defined in:
lib/or2d/cameras/centered.rb

Overview

Since:

  • 2023-04-26

Instance Attribute Summary

Attributes inherited from OR2D::Camera

#target, #viewport

Instance Method Summary collapse

Methods inherited from OR2D::Camera

#scroll_east, #scroll_north, #scroll_south, #scroll_west

Constructor Details

#initialize(target = nil) ⇒ CenteredCamera

Returns a new instance of CenteredCamera.

Since:

  • 2023-04-26



3
4
5
6
7
8
# File 'lib/or2d/cameras/centered.rb', line 3

def initialize(target = nil)
  super(OR2D.game.screen_width, OR2D.game.screen_height, target, 1.scale)
  orientate
  @scrolling = false
  @direction = nil
end

Instance Method Details

#orientateObject

Since:

  • 2023-04-26



30
31
32
33
# File 'lib/or2d/cameras/centered.rb', line 30

def orientate
  @target.screen_x = OR2D.game.screen_width / 2
  @target.screen_y = OR2D.game.screen_height / 2
end

#reset_scrollingObject

Since:

  • 2023-04-26



35
36
37
# File 'lib/or2d/cameras/centered.rb', line 35

def reset_scrolling
  @scrolling = false
end

#scroll(direction, amount) ⇒ Object

Since:

  • 2023-04-26



24
25
26
27
28
# File 'lib/or2d/cameras/centered.rb', line 24

def scroll(direction, amount)
  @scrolling = true
  @direction = direction
  @speed = amount
end

#updateObject

Since:

  • 2023-04-26



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/or2d/cameras/centered.rb', line 10

def update
  orientate
  return unless @scrolling

  case @direction
  when :north then scroll_north(@speed, false)
  when :south then scroll_south(@speed, false)
  when :east then scroll_east(@speed, false)
  when :west then scroll_west(@speed, false)
  end

  reset_scrolling
end