Class: Camera2D

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(offset, target, rotation, zoom) ⇒ Camera2D

Creates a new instance of Camera2D

Parameters:



8
9
10
11
12
# File 'mrb_doc/models/camera2d.rb', line 8

def initialize(offset, target, rotation, zoom)
  # mrb_Camera2D_initialize
  # src/mruby_integration/models/camera2d.cpp
  Camera2D.new
end

Instance Attribute Details

#offsetVector2

Returns:



4
5
6
# File 'src/ruby/models/camera2d.rb', line 4

def offset
  @offset
end

#rotationFloat

Returns:

  • (Float)


7
8
9
# File 'src/ruby/models/camera2d.rb', line 7

def rotation
  @rotation
end

#targetVector2

Returns:



4
5
6
# File 'src/ruby/models/camera2d.rb', line 4

def target
  @target
end

#zoomFloat

Returns:

  • (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.

Parameters:

Returns:



52
53
54
# File 'src/ruby/models/camera2d.rb', line 52

def as_in_viewport(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.

Parameters:

Returns:



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

Yields:

  • The block that calls your rendering logic

Returns:

  • (nil)


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_hHash

Return the object represented by a Hash

Returns:

  • (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