Class: Kawaii::Camera

Inherits:
Object
  • Object
show all
Defined in:
lib/kawaii/camera.rb

Instance Method Summary collapse

Constructor Details

#initialize(game) ⇒ Camera

Returns a new instance of Camera.



4
5
6
7
8
9
10
# File 'lib/kawaii/camera.rb', line 4

def initialize game
	@game = game
	@pos = Vector2.new
	@origin = Vector2.new(@game.width / 2, @game.height / 2)
	@destination = Vector2.new
	@speed = 0.05
end

Instance Method Details

#move(x, y) ⇒ Object



12
13
14
15
16
# File 'lib/kawaii/camera.rb', line 12

def move x, y
	@destination.x, @destination.y = x - @origin.x, y - @origin.y
	@pos.x = Kawaii::lerp(@pos.x, @destination.x, @speed)
	@pos.y = Kawaii::lerp(@pos.y, @destination.y, @speed)	
end

#translate(&block) ⇒ Object



18
19
20
21
22
# File 'lib/kawaii/camera.rb', line 18

def translate(&block)
	@game.translate(@pos.x, @pos.y) do
		block.call()
	end
end