mspraggs / potentia

Southampton Game Jam 2015
0 stars 0 forks source link

Parallax Background #65

Closed DivFord closed 9 years ago

DivFord commented 9 years ago

Parallax backgrounds are on my list of graphical improvements. I now have all the art I need for it, but I'm going to need to set up the code.

@Fyll, could you explain how your view-scrolling works, and where it is?

Fyll commented 9 years ago

In Screen::draw(), the Window::draw() takes 3 parameters. The first is the texture id (no need to touch that), the second is the position on the screen, and the third is the dimensions (on the screen) of the image. At the moment, it's drawn at (0, 0), and goes all the way across to (1, 1) (aka, it's drawn over the full screen).

There are two ways you could do a parallax effect:

Of the two, I think the second one is probably better (I can't say how intuitive they are though), as I'm a bit iffy on the idea of drawing the whole BG, but having a sizeable chunk of it off screen.

The pos_ or pos() variable can be used to determine the position of the top-left corner of the level. It's at (0, 0) when the screen is the top-left chunk of the level, and, if the level is two screen widths wide and two screen heights high, it'll be at (1, 1) when it's in the bottom-right corner. Basically, the position of the screen is given in absolute coordinates in the level, with units of screen dimensions.

EDIT: As an example, if the level has n times the dimensions of the screen, but the BG has m times the dimensions of the screen, a simple parallax effect could be done by (I haven't tested these, but I think they should work):

Window::instance().draw(tex_, -1.0f * pos_ * (m - 1) / (n - 1), Vector(m, m));

or,

Window::instance().draw(tex_, Vector::Zeros(), Vector::Ones(), Vector::Ones() * pos_ / (m * (n - 1)), Vector::Ones() / m);
DivFord commented 9 years ago

@Fyll PATH_BG in FilePaths.hpp seems to be a vector. Is the idea that the vector contains both layers of the background, or should I be making a new variable?

Fyll commented 9 years ago

That was expected to contain the BG for each of the worlds. I hadn't planned parallax BGs that far ahead. That's probably going to be redone when more worlds are created (probably shifted into a WorldList.hpp like everything else), so do whatever's easiest for now.

DivFord commented 9 years ago

Where can I get the size of the level relative to the screen? (the m in your description above). This is from Screen.hpp.

Fyll commented 9 years ago

It's the variable dim_ (see the comment above the constructor).

DivFord commented 9 years ago

So it is. Perfect.