Class: Plane

Inherits:
Object
  • Object
show all
Defined in:
lib/openrgss/plane.rb

Overview

# The Plane class. Planes are special sprites that tile bitmap patterns across the entire screen and are used to display parallax backgrounds and so on.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg_viewport = nil) ⇒ Plane

Creates a Plane object. Specifies a viewport (Viewport) when necessary.



43
44
45
46
# File 'lib/openrgss/plane.rb', line 43

def initialize(arg_viewport=nil)
  @sprite = Sprite.new(arg_viewport)
  @src_bitmap = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



98
99
100
# File 'lib/openrgss/plane.rb', line 98

def method_missing(symbol, *args)
  @sprite.method(symbol).call(*args)
end

Instance Attribute Details

#oxObject

The x-coordinate of the plane’s starting point. Change this value to scroll the plane.



19
20
21
# File 'lib/openrgss/plane.rb', line 19

def ox
  @ox
end

#oyObject

The y-coordinate of the plane’s starting point. Change this value to scroll the plane.



22
23
24
# File 'lib/openrgss/plane.rb', line 22

def oy
  @oy
end

Instance Method Details

#bitmapObject



72
73
74
# File 'lib/openrgss/plane.rb', line 72

def bitmap
  @src_bitmap
end

#bitmap=(arg_bmp) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/openrgss/plane.rb', line 77

def bitmap=(arg_bmp)
  vp_width = @sprite.viewport.nil? ? \
                          Graphics.width : @sprite.viewport.rect.width
  vp_height = @sprite.viewport.nil? ? \
                          Graphics.height : @sprite.viewport.rect.height
  x_steps = [(vp_width / arg_bmp.width).ceil, 1].max * 2
  y_steps = [(vp_height / arg_bmp.height).ceil, 1].max * 2

  bmp_width = x_steps * arg_bmp.width
  bmp_height = y_steps * arg_bmp.height

  @src_bitmap = arg_bmp
  @sprite.bitmap.dispose unless @sprite.bitmap.nil? or @sprite.bitmap.disposed?
  @sprite.bitmap = Bitmap.new(bmp_width, bmp_height)

  x_steps.times { |ix| y_steps.times { |iy|
    @sprite.bitmap.blt(ix * arg_bmp.width, iy * arg_bmp.height,
                       @src_bitmap, @src_bitmap.rect)
  } }
end

#disposeObject

Frees the plane. If the plane has already been freed, does nothing.



50
51
52
53
# File 'lib/openrgss/plane.rb', line 50

def dispose
  @sprite.bitmap.dispose unless @sprite.bitmap.nil? or @sprite.bitmap.disposed?
  @sprite.dispose unless @sprite.nil? or @sprite.disposed?
end

#disposed?Boolean

Returns TRUE if the plane has been freed.

Returns:

  • (Boolean)


57
58
59
# File 'lib/openrgss/plane.rb', line 57

def disposed?
  @sprite.nil? or @sprite.disposed?
end