Sha256: 294446393eb1445d0abf48a2f38843016d513483b45530e554b6fd7041d5bd15

Contents?: true

Size: 795 Bytes

Versions: 1

Compression:

Stored size: 795 Bytes

Contents

# Ruby2D::Image

module Ruby2D
  class Image
    include Renderable

    attr_reader :path, :color
    attr_accessor :x, :y, :width, :height, :rotate, :data

    def initialize(path, opts = {})
      @path = path

      unless RUBY_ENGINE == 'opal'
        unless File.exists? @path
          raise Error, "Cannot find image file `#{@path}`"
        end
      end

      @x = opts[:x] || 0
      @y = opts[:y] || 0
      @z = opts[:z] || 0
      @width = opts[:width] || nil
      @height = opts[:height] || nil
      @rotate = opts[:rotate] || 0
      self.color = opts[:color] || 'white'

      ext_init(@path)
      add
    end

    def color=(c)
      @color = Color.new(c)
    end

    def contains?(x, y)
      @x < x and @x + @width > x and @y < y and @y + @height > y
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby2d-0.7.0 lib/ruby2d/image.rb