ippa/chingu

Parallax and Viewpoint problem!

Closed this issue · 6 comments

I'm trying to use a simple parallax in a viewport example21_sidescroller_with_edit.rb similar to, but when I walk too much parallax repeated stops, these two traits are incompatible? and tested in various ways and nothing.

At first he repetipe several times but when I move a lot of stops and the only thing left is the black background of the viewport. Any help?

Sorry for the bad English :)

Basically, this is what I'm doing:

class Nivel1 < GameState
traits :viewport

def initialize(options = {})
super
self.input = {:e => :edit}
self.viewport.game_area = [0, 0, 3000, HEIGHT]

@parallax = Chingu::Parallax.create(:x => 0, :y => 0, :rotation_center => :top_left)
@parallax.add_layer(
  :image => "space.png",
  :repeat_x => true,
  :repeat_y => false,
  :damping => 5
)

load_game_objects
@player = Player.create

end

def edit
push_game_state(GameStates::Edit.new(
:grid => [32,32], #tamaño de las rejillas en el modo editor.
:classes => [
Player,
Rocks,
Water
]))
end

def update
super
self.viewport.center_around(@player)
@parallax.camera_x, @parallax.camera_y = self.viewport.x, self.viewport.y
end
end

ippa commented

Hi. Could you provide a full runnable code example in a gist or pastie that demonstrates this error? Either use gfx that's in chingus examples\media-dir or provide downloadlinks to the gfx. I'll check it out and find out why it doesn't work.

Sorry for the delay, here I leave a link to download a basic example of what happens when I want to use parallax to viewport. When executed you can see clearly that after walking a stretch, the parallax image repeated stops.

The link: http://www.megaupload.com/?d=9MP5KDGE

I hope his assist, greetings.

ippa commented

Yes, the problem is that viewport-trait automatiaclly draws every object (created with Model.create) with an offset. This confuses the parallax scroller.

The sollution is to use .new instead of .create like this:
@parallax = Chingu::Parallax.new(:x => 0, :y => 0, :rotation_center => :top_left)

Then:

def update
....
@parallax.camera_x, @parallax.camera_y = self.viewport.x.to_i, self.viewport.y.to_i
@parallax.update
end

def draw
@parallax.draw
super
end

I'll make a note of this in the Readme.

ippa commented

I succeeded in formating my code bad too :):

Here's is the new working nive1.rb-file http://pastie.org/1598473

Thanks a lot for the help, works perfectly!, now the parallax slides, never ends and I can appreciate having a good performance :) . Now I have another question, and tried fairly and I can not find it: how I can flip images horizontally? Because all I can do is to rotate with the method 'angle' and if I put the negative factor but also make a rotation but not turned horizontally (or vertically).

ippa commented

game_object.factor_x = -1