Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallax and Viewport compatibilities #55

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Parallax and Viewport compatibilities #55

wants to merge 5 commits into from

Conversation

jamillosantos
Copy link

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

Without Viewport

The example3_parallax.rb default examples works.

With Viewport

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

Solved the incompatibilities between parallaxes and viewport. Some samples was been tested, include the example3_parallax.rb, found on default examples.

To use the Parallax with Viewport you must change the properties camera_x and/or camera_y from Parallax, ever that you change the Viewport boundaries.
@ippa
Copy link
Owner

ippa commented Aug 23, 2012

Hi, thanks for taking the time to make this pullrequest! Have you done any other testing then that single example? Would it be possible with a few testcases? I don't want to brake anyones game.

@jamillosantos
Copy link
Author

Thanks. All right, I will collect some examples on google and make a bunch of testcases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants