Class: Chingu::ParallaxLayer
- Inherits:
-
GameObject
- Object
- BasicGameObject
- GameObject
- Chingu::ParallaxLayer
- Defined in:
- lib/chingu/parallax.rb
Overview
ParallaxLayer is mainly used by class Parallax to keep track of the different layers. If you @parallax << { :image => "foo.png" } a ParallaxLayer will be created automaticly from that Hash.
If no zorder is provided the ParallaxLayer-class increments an internal zorder number which will put the last layer added on top of the rest.
Instance Attribute Summary collapse
-
#damping ⇒ Object
readonly
Returns the value of attribute damping.
-
#repeat_x ⇒ Object
Returns the value of attribute repeat_x.
-
#repeat_y ⇒ Object
Returns the value of attribute repeat_y.
Attributes inherited from BasicGameObject
Instance Method Summary collapse
-
#get_pixel(x, y) ⇒ Object
Gets pixel from layers image The pixel is from the window point of view, so coordinates are converted:.
-
#initialize(options) ⇒ ParallaxLayer
constructor
A new instance of ParallaxLayer.
Methods included from Helpers::InputClient
#add_inputs, #holding?, #holding_all?, #holding_any?, #input, #input=, #on_input
Methods inherited from BasicGameObject
all, create, #destroy, destroy_all, destroy_if, #draw, #draw_trait, each, each_with_index, #filename, initialize_trait, #pause!, #paused?, select, #setup, #setup_trait, size, trait, #trait_options, traits, #unpause!, #update, #update_trait
Methods included from Helpers::ClassInheritableAccessor
Constructor Details
#initialize(options) ⇒ ParallaxLayer
Returns a new instance of ParallaxLayer.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/chingu/parallax.rb', line 165 def initialize() @parallax = [:parallax] # No auto update/draw, the parentclass Parallax takes care of that! .merge!(:visible => false, :paused => true) = {:rotation_center => @parallax.[:rotation_center]}.merge() if @parallax # # Default arguments for repeat_x and repeat_y # If no zorder is given, use a global incrementing counter. # First added, furthest behind when drawn. # = { :repeat_x => true, :repeat_y => false, :zorder => @parallax ? (@parallax.zorder + @parallax.layers.count) : 100 }.merge() @repeat_x = [:repeat_x] @repeat_y = [:repeat_y] super() @damping = [:damping] || 1 end |
Instance Attribute Details
#damping ⇒ Object (readonly)
Returns the value of attribute damping.
162 163 164 |
# File 'lib/chingu/parallax.rb', line 162 def damping @damping end |
#repeat_x ⇒ Object
Returns the value of attribute repeat_x.
163 164 165 |
# File 'lib/chingu/parallax.rb', line 163 def repeat_x @repeat_x end |
#repeat_y ⇒ Object
Returns the value of attribute repeat_y.
163 164 165 |
# File 'lib/chingu/parallax.rb', line 163 def repeat_y @repeat_y end |
Instance Method Details
#get_pixel(x, y) ⇒ Object
Gets pixel from layers image The pixel is from the window point of view, so coordinates are converted:
@parallax.layers.first.get_pixel(10, 10) # the visible pixel at 10, 10
@parallax.layers.first.image.get_pixel(10, 10) # gets pixel 10, 10 from layers image no matter where layer is positioned
198 199 200 201 202 203 204 205 206 |
# File 'lib/chingu/parallax.rb', line 198 def get_pixel(x, y) image_x = x - @x image_y = y - @y # On a 100 x 100 image, get_pixel works to 99 x 99 image_x -= @image.width while image_x >= @image.width @image.get_pixel(image_x, image_y) end |