Saturday, November 30, 2019

Question About An Implementation Of Parallax Scrolling In C++/SDL/OpenGL


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.



Answer



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[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.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...