Class: RGame::Engine::Components::Sprite
- Inherits:
-
RGame::Engine::Component
- Object
- RGame::Engine::Component
- RGame::Engine::Components::Sprite
- Includes:
- RGame::Engine::Culling
- Defined in:
- lib/rgame/engine/components/sprite.rb
Overview
Draws a single registered image centered on the node's absolute origin. It passes NO angle to the renderer: Node2D#draw already wraps a node's own draws in renderer.rotated(abs_angle, abs_x, abs_y), so the node's rotation orients the sprite — passing an angle here too would rotate it twice.
scale is writable so a pooled entity (e.g. a multi-tier rock) can retune it on
reset. z is the render layer (NOT the node's transform z / abs_z) — kept under
renderer.sprite), add a sibling AnimatedSprite component later.
Instance Attribute Summary collapse
-
#scale ⇒ Object
Returns the value of attribute scale.
Attributes inherited from RGame::Engine::Component
Instance Method Summary collapse
-
#draw(renderer, view) ⇒ Object
Centred on the node's origin and scaled, so the footprint to cull against is the node's box scaled and offset back by half of itself.
-
#initialize(id:, scale: 1.0, z: 0) ⇒ Sprite
constructor
A new instance of Sprite.
Methods inherited from RGame::Engine::Component
#context, #control, #on_attach, #on_detach, #sweep_freed, #update
Methods included from Signal::DSL
Constructor Details
#initialize(id:, scale: 1.0, z: 0) ⇒ Sprite
Returns a new instance of Sprite.
20 21 22 23 24 25 |
# File 'lib/rgame/engine/components/sprite.rb', line 20 def initialize(id:, scale: 1.0, z: 0) super() @id = id @scale = scale @layer = z end |
Instance Attribute Details
#scale ⇒ Object
Returns the value of attribute scale.
18 19 20 |
# File 'lib/rgame/engine/components/sprite.rb', line 18 def scale @scale end |
Instance Method Details
#draw(renderer, view) ⇒ Object
Centred on the node's origin and scaled, so the footprint to cull against is the node's box scaled and offset back by half of itself. A node that never set a size is never culled — see Culling.
30 31 32 33 34 35 36 37 |
# File 'lib/rgame/engine/components/sprite.rb', line 30 def draw(renderer, view) width = node.width * @scale height = node.height * @scale return if culled?(view, node.abs_x - (width / 2.0), node.abs_y - (height / 2.0), width, height) renderer.image(@id, node.abs_x, node.abs_y, scale: @scale, z: @layer) end |