Class: RGame::Engine::Components::ScreenWrap
- Inherits:
-
RGame::Engine::Component
- Object
- RGame::Engine::Component
- RGame::Engine::Components::ScreenWrap
- 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
Instance Method Summary collapse
-
#initialize(width:, height:, margin: 0.0) ⇒ ScreenWrap
constructor
A new instance of ScreenWrap.
- #update(_dt) ⇒ Object
Methods inherited from RGame::Engine::Component
#context, #control, #draw, #on_attach, #on_detach, #sweep_freed
Methods included from Signal::DSL
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 |