Class: RGame::Engine::Components::ScreenWrap

Inherits:
RGame::Engine::Component show all
Defined in:
lib/rgame/engine/components/screen_wrap.rb

Overview

Wraps the node's position toroidally within a rectangle (plus margin), so an entity leaving one edge reappears on the opposite one. From Body#wrap!. The bounds are passed in; in a scrolling game they'd come from a scene-scoped World system instead.

Instance Attribute Summary

Attributes inherited from RGame::Engine::Component

#node

Instance Method Summary collapse

Methods inherited from RGame::Engine::Component

#context, #control, #draw, #on_attach, #on_detach, #sweep_freed

Methods included from Signal::DSL

#signal

Constructor Details

#initialize(width:, height:, margin: 0.0) ⇒ ScreenWrap

Returns a new instance of ScreenWrap.



11
12
13
14
15
16
# File 'lib/rgame/engine/components/screen_wrap.rb', line 11

def initialize(width:, height:, margin: 0.0)
  super()
  @width = width
  @height = height
  @margin = margin
end

Instance Method Details

#update(_dt) ⇒ Object



18
19
20
21
22
23
# File 'lib/rgame/engine/components/screen_wrap.rb', line 18

def update(_dt)
  node.x = @width + @margin if node.x < -@margin
  node.x = -@margin if node.x > @width + @margin
  node.y = @height + @margin if node.y < -@margin
  node.y = -@margin if node.y > @height + @margin
end