TIGSource Forums

Developer => Technical => Topic started by: NandoSoft on February 03, 2010, 03:33:30 PM



Title: Vertical Parallax
Post by: NandoSoft on February 03, 2010, 03:33:30 PM
Hi guys Im trying to make my layers to move vertically at different speeds whenver the camera moves on the Y axis (like in sonic)

problem is I dont want the layers to move too far from their orginal location

another problem Im having is since I have really tall levels my math goes off charts because I use as a speed factor a value like = camera.positionY * yScrollSpeed


ideas??


Title: Re: Vertical Parallax
Post by: bateleur on February 04, 2010, 06:12:22 AM
ideas??

Work out the furthest you're prepared to have each layer scroll and move it by the fraction of that maximum corresponding to the ratio of the character's current y position compared to maximum y position.


Title: Re: Vertical Parallax
Post by: NandoSoft on February 04, 2010, 06:24:29 AM
so lets say

layer to move            = layer
original position        = position
max_offset               = position.Y - layer.texture.height * 0.25 (maximum allowed)
game level size          = dimensions
charcter                 = camera (camera is always focusing on character)

then



layer.position.y = max_offset * camera.Y / dimensions.Height


??????????


Im not at home right now so I cant try it and see if it works


Title: Re: Vertical Parallax
Post by: Martin 2BAM on February 04, 2010, 06:42:18 AM
You will always have layers moving far from the original position, that's what makes the parallaxing 2.5D effect.

What you can do is also define the center of the level so everything in the backgroudn moves relative to that (and when you're at the center, they are "aligned" to their real positions)


Try something like this:
Code:
draw.x = position.x + (camera.x-levelCenter.x) * scrollingFactor.x
draw.y = position.y + (camera.y-levelCenter.y) * scrollingFactor.y

Scrolling factor works like this:
     0 -non-moving... really far away
  (0;1)-background moving at different speeds
     1 -camera following, this is the main plane
(1;inf)- foreground moving faster than the camera




Title: Re: Vertical Parallax
Post by: NandoSoft on February 04, 2010, 07:00:28 AM
Oh yes totally forgot about having the center of the level as a reference

although it will only work for the x axis because Im using the bottom of the level as a baseline for placing all of my background layers and not the center



Title: Re: Vertical Parallax
Post by: Martin 2BAM on February 04, 2010, 07:21:34 AM
It doesn't matter, just set the levelCenter.y somewhere else :)


Title: Re: Vertical Parallax
Post by: NandoSoft on February 04, 2010, 12:29:27 PM
Yes of course!!  :biglaff:


Title: Re: Vertical Parallax
Post by: NandoSoft on February 08, 2010, 04:13:58 AM
I was wondering if there was a formula to calculate how big my background layers should be in order to avoid gaps when moving the camera around..

You will always have layers moving far from the original position, that's what makes the parallaxing 2.5D effect.

What you can do is also define the center of the level so everything in the backgroudn moves relative to that (and when you're at the center, they are "aligned" to their real positions)


Try something like this:
Code:
draw.x = position.x + (camera.x-levelCenter.x) * scrollingFactor.x
draw.y = position.y + (camera.y-levelCenter.y) * scrollingFactor.y

Scrolling factor works like this:
    0 -non-moving... really far away
  (0;1)-background moving at different speeds
     1 -camera following, this is the main plane
(1;inf)- foreground moving faster than the camera





Title: Re: Vertical Parallax
Post by: Martin 2BAM on February 08, 2010, 07:57:34 AM
1/scrollFactor.x and 1/scrollFactor.y times the size of the "normal" (scroll factors = 1.0) layers, for width and height respectively.


Title: Re: Vertical Parallax
Post by: NandoSoft on February 08, 2010, 11:27:12 AM
thank you man  :beer:

ill post a video of how things are coming along


Title: Re: Vertical Parallax
Post by: NandoSoft on February 08, 2010, 11:50:15 AM
Okay Ive manage to somehow get it working

by somehow I mean that the values are completely off

for example if the scroll factor is set to 1 the layer remains static (always on screen)

0 follows camera , -1 double speed, -2 triple speed etc..

is it because Im using tiles for rendering my background layers??

Code:
                offset_x = current_layer.Position.X + (Camera.Location.X - Dimensions.Center.X) * current_layer.Depth;
                offset_y = current_layer.Position.Y;

                if (current_layer.Tileable)
                {
                    for (float idx = offset_x; idx <= Dimensions.Width + Math.Abs(offset_x); idx += current_layer.Texture.Width)                   
                    {
                        if (idx >= start_pos_x && idx <= end_pos_x) // could be further optimized by checking the y-coordinate
                        {
                            SBatch.Draw(current_layer.Texture, new Vector2(idx, offset_y), Color.White);
                            draw_calls++;
                        }
                    }
                }


Title: Re: Vertical Parallax
Post by: Mikademus on February 08, 2010, 12:57:45 PM
This is more than slightly off-topic, but if you need inspiration to keep drudging on, take a look at this longplay:

http://www.youtube.com/watch?v=uiAUZe_kL_Y&NR=1

At about 11 minutes it has perhaps the best parallax scroll ever made :)

(It is Psygnosis' Shadow of the Beast, if you wonder)


Title: Re: Vertical Parallax
Post by: pgil on February 08, 2010, 03:38:14 PM
The graphics are really too good for such a boring game.