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.
Constant Summary collapse
- @@zorder_counter =
0
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 GameObject
#angle, #center, #center_x, #center_y, #color, #factor, #factor_x, #factor_y, #image, #mode, #x, #y, #zorder
Attributes inherited from BasicGameObject
#options, #parent, #paused, #visible
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 inherited from GameObject
#alpha, #alpha=, #distance_to, #draw, #inside_window?, #outside_window?
Methods included from Helpers::RotationCenter
#rotation_center, #rotation_center=
Methods included from Helpers::InputClient
Methods inherited from BasicGameObject
all, create, #destroy, destroy_all, destroy_if, #draw, #draw_trait, has_trait, has_traits, #hide!, initialize_trait, #pause!, #paused?, #setup_trait, #show!, size, #trait_options, #unpause!, #update, #update_trait, #visible?
Methods included from Helpers::ClassInheritableAccessor
Constructor Details
#initialize(options) ⇒ ParallaxLayer
Returns a new instance of ParallaxLayer.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/chingu/parallax.rb', line 168 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 => (@@zorder_counter+=1) }.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.
165 166 167 |
# File 'lib/chingu/parallax.rb', line 165 def damping @damping end |
#repeat_x ⇒ Object
Returns the value of attribute repeat_x.
166 167 168 |
# File 'lib/chingu/parallax.rb', line 166 def repeat_x @repeat_x end |
#repeat_y ⇒ Object
Returns the value of attribute repeat_y.
166 167 168 |
# File 'lib/chingu/parallax.rb', line 166 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
202 203 204 205 206 207 208 209 210 |
# File 'lib/chingu/parallax.rb', line 202 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 |