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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Francismoy

Pages: [1]
1
Graphics / 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.

Pages: [1]