Class: Slickr::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/slickr/renderer.rb

Overview

Renderers take the current state of an entity and draws it to the screen.

Never Mutate Entities

Renderers should know as little as possible about the entity it’s drawing. They should also never, ever, mutate an entity. They only request information and push a representation of that to the screen.

Examples:

Simple renderer that draws a graphic on the screen


class HeroRenderer < Slickr::Renderer
  attr_reader :image

  def initialize(entity)
    super
    @image = Image.new("assets/hero.png", false)
  end

  def render
    image.draw(entity.x, entity.y)
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity) ⇒ Renderer

Returns a new instance of Renderer.



29
30
31
# File 'lib/slickr/renderer.rb', line 29

def initialize(entity)
  @entity = entity
end

Instance Attribute Details

#entityObject (readonly)

Returns the value of attribute entity.



27
28
29
# File 'lib/slickr/renderer.rb', line 27

def entity
  @entity
end

Instance Method Details

#renderObject

Raises:



33
34
35
# File 'lib/slickr/renderer.rb', line 33

def render
  raise NotImplementedError
end