Class: SlideField::ObjectManager::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/slidefield/objects/image.rb

Instance Method Summary collapse

Methods inherited from Base

#execute, #initialize, #method_missing, #on_activate, #on_deactivate

Constructor Details

This class inherits a constructor from SlideField::ObjectManager::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SlideField::ObjectManager::Base

Instance Method Details

#on_draw(animator) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/slidefield/objects/image.rb', line 31

def on_draw(animator)
  tr = animator.transform @obj
  return if tr.skip_draw?

  x = @x + tr.x_offset
  y = @y + tr.y_offset

  x_scale = tr.scale * @x_scale
  y_scale = tr.scale * @y_scale

  color = @color.dup
  color.alpha = tr.opacity * @color.alpha

  @image.draw x, y, @z, x_scale, y_scale, color
end

#on_loadObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/slidefield/objects/image.rb', line 15

def on_load
  @x, @y = @obj.get :position
  @z = @obj.get :z_order
  @color = Gosu::Color.rgba *@obj.get(:color)

  source = File.expand_path @obj.get(:source), @obj.include_path
  width, height = @obj.get :size

  @image = Gosu::Image.new @window, source, true
  width = @image.width if 0 == width
  height = @image.height if 0 == height

  @x_scale = width / @image.width.to_f
  @y_scale = height / @image.height.to_f
end

#on_unloadObject



47
48
49
# File 'lib/slidefield/objects/image.rb', line 47

def on_unload
  @image = nil
end