summaryrefslogtreecommitdiffhomepage
path: root/lib/ruby2d/image.rb
blob: 85ee076fa16bca11df334ff40ce9467d05c03040 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# image.rb

module Ruby2D
  class Image
    include Renderable

    attr_accessor :x, :y, :width, :height, :data
    attr_reader :path, :color
    
    def initialize(x, y, path, z=0)
      
      unless RUBY_ENGINE == 'opal'
        unless File.exists? path
          raise Error, "Cannot find image file `#{path}`"
        end
      end
      
      @type_id = 3
      @x, @y, @path = x, y, path
      @z = z
      @color = Color.new([1, 1, 1, 1])
      init(path)
      add
    end
    
    def color=(c)
      @color = Color.new(c)
    end
  end
end