Sha256: 0faad98b2e5ab74e49dec719e357fe2aaac4f7c183b1139dff5acaeaabc37d6c

Contents?: true

Size: 1.19 KB

Versions: 7

Compression:

Stored size: 1.19 KB

Contents

# Ruby2D::Renderable

module Ruby2D
  module Renderable

    attr_reader :x, :y, :z, :width, :height, :color

    # Set the z position (depth) of the object
    def z=(z)
      remove
      @z = z
      add
    end

    # Add the object to the window
    def add
      if Module.const_defined? :DSL
        Window.add(self)
      end
    end

    # Remove the object from the window
    def remove
      if Module.const_defined? :DSL
        Window.remove(self)
      end
    end

    # Set the color value
    def color=(c)
      @color = Color.new(c)
    end

    # Allow British English spelling of color
    def colour; self.color end
    def colour=(c); self.color = c end

    # Allow shortcuts for setting color values
    def r; self.color.r end
    def g; self.color.g end
    def b; self.color.b end
    def a; self.color.a end
    def r=(c); self.color.r = c end
    def g=(c); self.color.g = c end
    def b=(c); self.color.b = c end
    def a=(c); self.color.a = c end
    def opacity; self.color.opacity end
    def opacity=(val); self.color.opacity = val end

    # Add a contains method stub
    def contains?(x, y)
      x >= @x && x <= (@x + @width) && y >= @y && y <= (@y + @height)
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ruby2d-0.9.5 lib/ruby2d/renderable.rb
ruby2d-0.9.4 lib/ruby2d/renderable.rb
ruby2d-0.9.3 lib/ruby2d/renderable.rb
ruby2d-0.9.2 lib/ruby2d/renderable.rb
ruby2d-0.9.1 lib/ruby2d/renderable.rb
ruby2d-0.9.0 lib/ruby2d/renderable.rb
ruby2d-0.8.1 lib/ruby2d/renderable.rb