Class: Background
- Inherits:
-
Object
- Object
- Background
- Defined in:
- lib/fantasy/background.rb
Overview
Instance Attribute Summary collapse
-
#layer ⇒ Object
In which layer the image of the Background is rendered.
-
#position ⇒ Object
Coordinates object where x and y represent the position of the Background in the World (no necessarily in the Screen).
-
#replicable ⇒ Object
[Boolean] When
true
the image will replicate itself to cover all the screen. -
#scale ⇒ Object
The value to scale the image of the Background when drawn.
-
#visible ⇒ Object
When
false
the Background won't be rendered in the next frame.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy this Background and it will not longer be rendered.
-
#height ⇒ Fixnum
The Background height in pixels.
-
#initialize(image_name:) ⇒ Background
constructor
Generates an Background with all the below default values: - position:
Coordinates.zero
. -
#width ⇒ Fixnum
The Background width in pixels.
Constructor Details
#initialize(image_name:) ⇒ Background
Generates an Background with all the below default values:
- position:
Coordinates.zero
. - scale:
1
. - draggable_on_debug:
true
. - layer:
-100
. - image: The Image generated by
image_name
- name: Same as
image_name
- visible:
true
- replicable:
true
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fantasy/background.rb', line 86 def initialize(image_name:) @image = Image.new(image_name) @position = Coordinates.zero @scale = 1 @visible = true @draggable_on_debug = true @dragging = false @layer = -100 @replicable = true Global.backgrounds.push(self) end |
Instance Attribute Details
#layer ⇒ Object
In which layer the image of the Background is rendered. Smaller numbers are rendered behind higher numbers.
Default -100
.
23 24 25 |
# File 'lib/fantasy/background.rb', line 23 def layer @layer end |
#position ⇒ Object
Coordinates object where x and y represent the position of the Background in the World (no necessarily in the Screen).
Default Coordinates.zero
.
39 40 41 |
# File 'lib/fantasy/background.rb', line 39 def position @position end |
#replicable ⇒ Object
[Boolean] When true
the image will replicate itself to cover all the screen. Default true
.
Default true
.
48 49 50 |
# File 'lib/fantasy/background.rb', line 48 def replicable @replicable end |
#scale ⇒ Object
this value affects the attributes width
and height
The value to scale the image of the Background when drawn.
If the value is 2
the image will rendered at double of size.
If the value is 0.5
the image will rendered at half of size.
Default 1
.
61 62 63 |
# File 'lib/fantasy/background.rb', line 61 def scale @scale end |
#visible ⇒ Object
When false
the Background won't be rendered in the next frame.
Default true
.
70 71 72 |
# File 'lib/fantasy/background.rb', line 70 def visible @visible end |
Instance Method Details
#destroy ⇒ Object
Destroy this Background and it will not longer be rendered
128 129 130 |
# File 'lib/fantasy/background.rb', line 128 def destroy Global.backgrounds.delete(self) end |
#height ⇒ Fixnum
Returns the Background height in pixels.
105 106 107 |
# File 'lib/fantasy/background.rb', line 105 def height @image.height * @scale end |
#width ⇒ Fixnum
Returns the Background width in pixels.
100 101 102 |
# File 'lib/fantasy/background.rb', line 100 def width @image.width * @scale end |