4
\$\begingroup\$

I been working in a project with a team for a Software Engineering class and we think that using the parallax scrolling will help our game to look really nice but we are not really sure if our idea for implementation it's the correct one, so I hope that someon will give us some guidance about our plan.

First, we have three classes, Level, Tileset, Layer, the first one has two vectors of Layers and Tilesets, so our idea is load all the data from a TMX file of the first level in a vector>, but we only draw the part of the map that it's currently in camera, so inside a cycle we draw every layer, but we're not sure how defined a velocity for each layer so the parallax scrolling works like it supposed.

Thanks for the attention and help.

Good day....

PD: If someone need more information, don't doubt in ask.

\$\endgroup\$
7
  • \$\begingroup\$ Maybe I don't really understand the problem. But each Parallax layer is really just a float for speed and a series of drawables attached to it with an offset. So you just do if(LayerSpeed*DrawableOffset is inside screen rect){draw drawable;}? Or is it something else that you're having trouble with? \$\endgroup\$
    – Roy T.
    Commented Sep 3, 2011 at 21:28
  • \$\begingroup\$ My problem is how move each layer at different velocity based on the position of the main character. Thanks for the reply... \$\endgroup\$
    – oscar.rpr
    Commented Sep 3, 2011 at 21:38
  • \$\begingroup\$ Simple an object's position is the object's offset from the left * the speed of the layer * the offset of the character from the left (here left is the start of the world). \$\endgroup\$
    – Roy T.
    Commented Sep 3, 2011 at 21:59
  • \$\begingroup\$ but how I determine how many tiles of the map moved when the translation occur...?? \$\endgroup\$
    – oscar.rpr
    Commented Sep 6, 2011 at 0:10
  • \$\begingroup\$ Sorry I don't get that question. Maybe you should read up a little more on parallax scrolling. See virtualrealm.com.au/Blog/tabid/62/EntryId/296/… for example (not C++ but might get the message across). \$\endgroup\$
    – Roy T.
    Commented Sep 6, 2011 at 8:44

3 Answers 3

2
\$\begingroup\$

Parallax scrolling is just using a set of layers moving with different speed. each layer can be a tilemap, just a sprite, or anything else. normally the most front layer is a tilemap and you only check collisions and other gameplay features with that layer. just keep in mind parallax scrolling is going to simulate 3d projection using only 2d objects, so objects back in the scene should move with slower speed than those in the front.

to ease your work,, you can keep the character(player) in some fixed position. then give negate of player velocity to your parallax node. I suggest for a parallax node you only change setPosition function, in that function instead of moving parallax node itself, you have to move all it's children, respecting their depth value. for example you can use some code like this one:

void move(float deltaX,float deltaY)
{
    for(unsigned i=0;i<children.size();i++)
    {
        children[i]->move(deltaX / child.depth,deltaY / child.depth);
    }
}

all the other functions of the parallax node is same as normal node. you don't need to worry about anything else.

\$\endgroup\$
4
  • \$\begingroup\$ I didn't understand the notion of parallax node?...Can you specify a little bit?? \$\endgroup\$
    – oscar.rpr
    Commented Sep 6, 2011 at 0:09
  • \$\begingroup\$ I guess you can find enough information in wiki page \$\endgroup\$
    – Ali1S232
    Commented Sep 6, 2011 at 8:29
  • \$\begingroup\$ @oscar : i've also added some more explanation to my answer, hope you get what you need. \$\endgroup\$
    – Ali1S232
    Commented Sep 7, 2011 at 5:30
  • \$\begingroup\$ Thanks Gajet, that extra information will help me a lot in the future... \$\endgroup\$
    – oscar.rpr
    Commented Sep 8, 2011 at 0:16
0
\$\begingroup\$

we're not sure how defined a velocity for each layer so the parallax scrolling works like it supposed.

Two floats. I'd recommend one for X and one for Y, but maybe your game happens in another coordinate system.

\$\endgroup\$
1
  • \$\begingroup\$ Yes, I understand that I must define a velocity value in each coordinate for the movement, my question is, how is the best way to use those variables for move the layers, because I have a matrix of each layer, and I draw every layer composed of tiles, but my main problem it's the way of move the layers... \$\endgroup\$
    – oscar.rpr
    Commented Sep 3, 2011 at 22:20
0
\$\begingroup\$

I've implemented it simply by having the lower background layer scroll at a certain speed, and having the upper background layer scroll at half the speed of the lower background.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .