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.
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
#distance_to, #draw, #inside_window?, #outside_window?
Methods included from Helpers::RotationCenter
Methods included from Helpers::InputClient
Methods inherited from BasicGameObject
all, create, #destroy, destroy_all, destroy_if, #draw, #draw_trait, has_trait, has_traits, #hide!, #pause!, #setup_trait, #show!, size, #unpause!, #update, #update_trait
Constructor Details
#initialize(options) ⇒ ParallaxLayer
Returns a new instance of ParallaxLayer.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/chingu/parallax.rb', line 105 def initialize() # No auto update/draw, the parentclass Parallax takes care of that! .merge!(:visible => false, :paused => true) # If no zorder is given, use a global incrementing counter. First added, furthest behind when drawn. .merge!(:zorder => (@@zorder_counter+=1)) if [:zorder].nil? super() @damping = [:damping] || 10 end |
Instance Attribute Details
#damping ⇒ Object (readonly)
Returns the value of attribute damping.
103 104 105 |
# File 'lib/chingu/parallax.rb', line 103 def damping @damping 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
124 125 126 127 128 129 130 131 132 |
# File 'lib/chingu/parallax.rb', line 124 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 |