Class: SpriteKit::Camera
- Inherits:
-
Object
- Object
- SpriteKit::Camera
- Defined in:
- mygame/lib/sprite_kit/camera.rb
Constant Summary collapse
- SCREEN_WIDTH =
1280
- SCREEN_HEIGHT =
720
Instance Attribute Summary collapse
-
#h ⇒ Object
Returns the value of attribute h.
-
#scale ⇒ Object
Returns the value of attribute scale.
-
#target_scale ⇒ Object
Returns the value of attribute target_scale.
-
#target_x ⇒ Object
Returns the value of attribute target_x.
-
#target_y ⇒ Object
Returns the value of attribute target_y.
-
#w ⇒ Object
Returns the value of attribute w.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #find_all_intersect_viewport(rects) ⇒ Object
-
#initialize(x: 0, y: 0, target_x: 0, target_y: 0, target_scale: 2, scale: 2, w: 1500, h: 1500) ⇒ Camera
constructor
A new instance of Camera.
- #intersect_viewport?(rect) ⇒ Boolean
- #offset_x ⇒ Object
- #offset_y ⇒ Object
- #to_screen_space(rect) ⇒ Object
- #to_world_space(rect) ⇒ Object
- #viewport ⇒ Object
- #viewport_world ⇒ Object
Constructor Details
#initialize(x: 0, y: 0, target_x: 0, target_y: 0, target_scale: 2, scale: 2, w: 1500, h: 1500) ⇒ Camera
Returns a new instance of Camera.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'mygame/lib/sprite_kit/camera.rb', line 8 def initialize( x: 0, y: 0, target_x: 0, target_y: 0, target_scale: 2, scale: 2, w: 1500, h: 1500 ) @x = x @y = y @target_x = target_x @target_y = target_y @target_scale = target_scale @scale = scale @w = w @h = h end |
Instance Attribute Details
#h ⇒ Object
Returns the value of attribute h.
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def h @h end |
#scale ⇒ Object
Returns the value of attribute scale.
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def scale @scale end |
#target_scale ⇒ Object
Returns the value of attribute target_scale.
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def target_scale @target_scale end |
#target_x ⇒ Object
Returns the value of attribute target_x.
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def target_x @target_x end |
#target_y ⇒ Object
Returns the value of attribute target_y.
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def target_y @target_y end |
#w ⇒ Object
Returns the value of attribute w.
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def w @w end |
#x ⇒ Object
Returns the value of attribute x.
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def y @y end |
Class Method Details
.to_screen_space(camera, rect) ⇒ Object
59 60 61 62 63 64 65 |
# File 'mygame/lib/sprite_kit/camera.rb', line 59 def self.to_screen_space(camera, rect) x = rect.x * camera.scale - camera.x * camera.scale + (camera.w / 2) y = rect.y * camera.scale - camera.y * camera.scale + (camera.h / 2) w = rect.w * camera.scale h = rect.h * camera.scale rect.merge x: x, y: y, w: w, h: h end |
.to_world_space(camera, rect) ⇒ Object
45 46 47 48 49 50 51 |
# File 'mygame/lib/sprite_kit/camera.rb', line 45 def self.to_world_space(camera, rect) x = (rect.x - (camera.w / 2) + camera.x * camera.scale - camera.offset_x) / camera.scale y = (rect.y - (camera.h / 2) + camera.y * camera.scale - camera.offset_y) / camera.scale w = rect.w / camera.scale h = rect.h / camera.scale rect.merge(x: x, y: y, w: w, h: h) end |
Instance Method Details
#find_all_intersect_viewport(rects) ⇒ Object
75 76 77 |
# File 'mygame/lib/sprite_kit/camera.rb', line 75 def (rects) Geometry.find_all_intersect_rect(, rects) end |
#intersect_viewport?(rect) ⇒ Boolean
79 80 81 |
# File 'mygame/lib/sprite_kit/camera.rb', line 79 def (rect) .intersect_rect?(rect) end |
#offset_x ⇒ Object
26 27 28 |
# File 'mygame/lib/sprite_kit/camera.rb', line 26 def offset_x (SCREEN_WIDTH - @w) / 2 end |
#offset_y ⇒ Object
30 31 32 |
# File 'mygame/lib/sprite_kit/camera.rb', line 30 def offset_y (SCREEN_HEIGHT - @h) / 2 end |
#to_screen_space(rect) ⇒ Object
67 68 69 |
# File 'mygame/lib/sprite_kit/camera.rb', line 67 def to_screen_space(rect) self.class.to_screen_space(self, rect) end |
#to_world_space(rect) ⇒ Object
53 54 55 |
# File 'mygame/lib/sprite_kit/camera.rb', line 53 def to_world_space(rect) self.class.to_world_space(self, rect) end |
#viewport ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'mygame/lib/sprite_kit/camera.rb', line 34 def { x: offset_x, y: offset_y, w: @w, h: @h } end |
#viewport_world ⇒ Object
71 72 73 |
# File 'mygame/lib/sprite_kit/camera.rb', line 71 def to_world_space() end |