Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: On Parallax Scrolling  (Read 2202 times)

0 Members and 1 Guest are viewing this topic.

Francismoy

  • Newbie
  • *
  • Posts: 6
    • View Profile
On Parallax Scrolling
« on: July 23, 2013, 09:22:55 am »
Hi all!

I submitted this question in an old post about parallax scrolling, but I didn't get an answer (the post was quite old, from 2011 or earlier I think).

I want to implement parallax scrolling. My approach is the following: I have two different classes, 'layer' and 'level'. A level is composed by a set of layers, and a layer is onto where the objects are drawn. During the level setup, I create its layers, and I assign a scroll velocity to each layer, which is actually a velocity of the view for that layer.

//Pseudo-code
layer1.setScrollVelocity(1.0f);
layer2.setScrollVelocity(0.5f); //layer 2 moves half slower than layer 1

In the update function of the frame, I update the position of all the objects in the layer and the movement of the layer itself by moving the view associated to the layer.

This seems to work fine for me, and has the expected effect, but I have another problem. I'd like to check whether I'm on any screen border in order to stop the movement of the layer. However, I don't know how to do this. If the layer (e.g. a background) is moving at a factor of 1.0, it's straightforward, as I can check if the position of the player is the size of the bitmap that fills the background. However, if the factor is less (and therefore is moving slower), I don't know how to check.

At the beginning, I assumed that if the background (view) moves at 0.5f, and the width of the background bitmap is 2000 pixels, I should arrive at the right border when the character is 4000, but this doesn't seem to work.

Any ideas?
Thanks in advance.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: On Parallax Scrolling
« Reply #1 on: July 23, 2013, 10:30:22 am »
You can check the position with the view of the second (slower) layer.

For example, you want to know if the border of your bitmap is reached

if( (view.getPosition().x + view.getSize().x) > 2000)
{
     //stop moving the view....
}
 



AlexAUT

Francismoy

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: On Parallax Scrolling
« Reply #2 on: July 23, 2013, 10:51:32 am »
Thanks for the quick answer! :)

I'll try it later and let you know the results.

 

anything