Class: SpriteKit::Camera
- Inherits:
-
Object
- Object
- SpriteKit::Camera
- Defined in:
- mygame/lib/sprite_kit/camera.rb
Instance Attribute Summary collapse
- #h ⇒ Object
- #offset_x ⇒ Object
- #offset_y ⇒ Object
-
#path ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720.
-
#scale ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720.
-
#target_scale ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720.
-
#target_x ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720.
-
#target_y ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720.
- #w ⇒ Object
-
#x ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720.
-
#y ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720.
Class Method Summary collapse
- .to_screen_space(camera, rect) ⇒ Object
- .to_screen_space!(camera, rect) ⇒ Object
- .to_world_space(camera, rect) ⇒ Object
- .to_world_space!(camera, rect) ⇒ Object
Instance Method Summary collapse
- #find_all_intersect_viewport(rects) ⇒ Object
- #half_height ⇒ Object
- #half_width ⇒ Object
-
#initialize(x: 0, y: 0, target_x: 0, target_y: 0, target_scale: 2, scale: 2, w: nil, h: nil, offset_x: nil, offset_y: nil, path: nil) ⇒ Camera
constructor
A new instance of Camera.
- #intersect_viewport?(rect) ⇒ Boolean
- #reset ⇒ Object
- #to_a ⇒ Object
- #to_screen_space(rect) ⇒ Object
- #to_screen_space!(rect) ⇒ Object
- #to_world_space(rect) ⇒ Object
- #to_world_space!(rect) ⇒ Object
- #viewport ⇒ Object
- #viewport_h ⇒ Object
- #viewport_h_half ⇒ Object
- #viewport_w ⇒ Object
- #viewport_w_half ⇒ Object
- #viewport_world ⇒ Object
Constructor Details
#initialize(x: 0, y: 0, target_x: 0, target_y: 0, target_scale: 2, scale: 2, w: nil, h: nil, offset_x: nil, offset_y: nil, path: nil) ⇒ Camera
Returns a new instance of Camera.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'mygame/lib/sprite_kit/camera.rb', line 9 def initialize( x: 0, y: 0, target_x: 0, target_y: 0, target_scale: 2, scale: 2, w: nil, h: nil, offset_x: nil, offset_y: nil, path: nil ) @x = x @y = y @target_x = target_x @target_y = target_y @target_scale = target_scale @scale = scale @w = w @h = h @offset_x = offset_x @offset_y = offset_y @path = path end |
Instance Attribute Details
#h ⇒ Object
35 36 37 |
# File 'mygame/lib/sprite_kit/camera.rb', line 35 def h @h || end |
#offset_x ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'mygame/lib/sprite_kit/camera.rb', line 75 def offset_x return @offset_x if @offset_x # old offset_x functionality when defining an @w return ( - @w / 2) if @w if Grid.origin_center? 0 else Grid.allscreen_x end end |
#offset_y ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'mygame/lib/sprite_kit/camera.rb', line 88 def offset_y return @offset_x if @offset_x # old offset_y functionality when defining an @h return ( - @h / 2) if @h if Grid.origin_center? 0 else Grid.allscreen_y end end |
#path ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def path @path end |
#scale ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def scale @scale end |
#target_scale ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def target_scale @target_scale end |
#target_x ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def target_x @target_x end |
#target_y ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def target_y @target_y end |
#w ⇒ Object
31 32 33 |
# File 'mygame/lib/sprite_kit/camera.rb', line 31 def w @w || end |
#x ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720
6 7 8 |
# File 'mygame/lib/sprite_kit/camera.rb', line 6 def x @x end |
#y ⇒ Object
SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720
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
172 173 174 |
# File 'mygame/lib/sprite_kit/camera.rb', line 172 def self.to_screen_space(camera, rect) to_screen_space!(camera, rect.merge({})) end |
.to_screen_space!(camera, rect) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'mygame/lib/sprite_kit/camera.rb', line 178 def self.to_screen_space!(camera, rect) if rect.x rect.x = rect.x * camera.scale - camera.x * camera.scale + (camera.half_width) end if rect.y rect.y = rect.y * camera.scale - camera.y * camera.scale + (camera.half_height) end if rect.w rect.w = rect.w * camera.scale end if rect.h rect.h = rect.h * camera.scale end rect end |
.to_world_space(camera, rect) ⇒ Object
138 139 140 |
# File 'mygame/lib/sprite_kit/camera.rb', line 138 def self.to_world_space(camera, rect) to_world_space!(camera, rect.merge({})) end |
.to_world_space!(camera, rect) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'mygame/lib/sprite_kit/camera.rb', line 142 def self.to_world_space!(camera, rect) if rect.x rect.x = (rect.x - (camera.half_width) + camera.x * camera.scale - camera.offset_x) / camera.scale end if rect.y rect.y = (rect.y - (camera.half_height) + camera.y * camera.scale - camera.offset_y) / camera.scale end if rect.w rect.w = rect.w / camera.scale end if rect.h rect.h = rect.h / camera.scale end rect end |
Instance Method Details
#find_all_intersect_viewport(rects) ⇒ Object
210 211 212 |
# File 'mygame/lib/sprite_kit/camera.rb', line 210 def (rects) Geometry.find_all_intersect_rect(, rects) end |
#half_height ⇒ Object
45 46 47 48 49 |
# File 'mygame/lib/sprite_kit/camera.rb', line 45 def half_height return @h.fdiv(2).ceil if @h end |
#half_width ⇒ Object
39 40 41 42 43 |
# File 'mygame/lib/sprite_kit/camera.rb', line 39 def half_width return @w.fdiv(2).ceil if @w end |
#intersect_viewport?(rect) ⇒ Boolean
214 215 216 |
# File 'mygame/lib/sprite_kit/camera.rb', line 214 def (rect) .intersect_rect?(rect) end |
#reset ⇒ Object
222 223 224 225 226 227 |
# File 'mygame/lib/sprite_kit/camera.rb', line 222 def reset @target_x = 0 @target_y = 0 @x = 0 @y = 0 end |
#to_a ⇒ Object
218 219 220 |
# File 'mygame/lib/sprite_kit/camera.rb', line 218 def to_a .merge!({}) end |
#to_screen_space(rect) ⇒ Object
198 199 200 |
# File 'mygame/lib/sprite_kit/camera.rb', line 198 def to_screen_space(rect) self.class.to_screen_space(self, rect) end |
#to_screen_space!(rect) ⇒ Object
202 203 204 |
# File 'mygame/lib/sprite_kit/camera.rb', line 202 def to_screen_space!(rect) self.class.to_screen_space!(self, rect) end |
#to_world_space(rect) ⇒ Object
162 163 164 |
# File 'mygame/lib/sprite_kit/camera.rb', line 162 def to_world_space(rect) self.class.to_world_space(self, rect) end |
#to_world_space!(rect) ⇒ Object
166 167 168 |
# File 'mygame/lib/sprite_kit/camera.rb', line 166 def to_world_space!(rect) self.class.to_world_space!(self, rect) end |
#viewport ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'mygame/lib/sprite_kit/camera.rb', line 101 def if @w && @h return { x: offset_x, y: offset_y, w: w, h: h, path: @path, primitive_marker: :sprite } end if Grid.origin_center? { x: offset_x, y: offset_y, w: w, h: h, anchor_x: 0.5, anchor_y: 0.5, path: @path, primitive_marker: :sprite } else { x: offset_x, y: offset_y, w: w, h: h, path: @path, primitive_marker: :sprite } end end |
#viewport_h ⇒ Object
51 52 53 |
# File 'mygame/lib/sprite_kit/camera.rb', line 51 def Grid.allscreen_h end |
#viewport_h_half ⇒ Object
67 68 69 70 71 72 73 |
# File 'mygame/lib/sprite_kit/camera.rb', line 67 def if Grid.origin_center? 0 else .fdiv(2).ceil end end |
#viewport_w ⇒ Object
55 56 57 |
# File 'mygame/lib/sprite_kit/camera.rb', line 55 def Grid.allscreen_w end |
#viewport_w_half ⇒ Object
59 60 61 62 63 64 65 |
# File 'mygame/lib/sprite_kit/camera.rb', line 59 def if Grid.origin_center? 0 else .fdiv(2).ceil end end |
#viewport_world ⇒ Object
206 207 208 |
# File 'mygame/lib/sprite_kit/camera.rb', line 206 def to_world_space() end |