ippa/chingu — pull request #55 by jamillosantos (2012-08-23 05:11:03+00:00)
Title: Parallax and Viewport compatibilities

Now the trait `:viewport` and `Parallax` can be used together.

## Without `Viewport`

The example3_parallax.rb default examples works.

## With `Viewport`

``` ruby
class GameStateTest < Chingu::GameState
traits :timer, :viewport

def initialize(options)
super(options)

self.viewport.lag = 0
self.viewport.game_area = [0.0, 0.0, 1000.0, 1000.0]

@parallaxes = []

tmp = Chingu::Parallax.create(:x => 0, :y => 0, :rotation_center => :top_left, :zorder => 1)
tmp.add_layer(:image => "grass.png", :damping => 10, :center => 0)
@parallaxes << tmp

tmp = Chingu::Parallax.create(:x => 0, :y => 283, :rotation_center => :top_left, :zorder => 2)
tmp << {:image => "grassfg.png", :y=>100, :damping => 1, :center => 0}
@parallaxes << tmp

tmp = Chingu::Parallax.create(:x => 0, :y => tmp.y-30, :rotation_center => :top_left, :zorder => 2)
tmp << {:image => "grassfg2.png", :y=>-100, :damping => 1, :center => 0}
@parallaxes << tmp

@bird = Player.create(:x => 200, :y => 0, :image => "player.png")
end
...
def update
self.viewport.center_around(@bird)
@parallaxes.each do |parallax|
parallax.camera_x = self.viewport.x
parallax.camera_y = self.viewport.y
end
super
end
...
end
```