Sha256: 38c6da389a03e13ca57ff27b90f00a6a9753e74e25839e9c80e84aa0f2c78bf4

Contents?: true

Size: 1.19 KB

Versions: 1

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

1 entries across 1 versions & 1 rubygems

Version Path
ruby2d-0.8.0 lib/ruby2d/renderable.rb