Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411659 Posts in 69395 Topics- by 58452 Members - Latest Member: Monkey Nuts

May 16, 2024, 01:37:59 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Vertical Parallax
Pages: [1]
Print
Author Topic: Vertical Parallax  (Read 2242 times)
NandoSoft
Level 1
*



View Profile
« 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??
Logged
bateleur
Level 10
*****



View Profile
« Reply #1 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.
Logged

NandoSoft
Level 1
*



View Profile
« Reply #2 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


Huh?Huh?Huh??


Im not at home right now so I cant try it and see if it works
Logged
Martin 2BAM
Level 10
*****


@iam2bam


View Profile WWW
« Reply #3 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


Logged

Working on HeliBrawl
NandoSoft
Level 1
*



View Profile
« Reply #4 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

Logged
Martin 2BAM
Level 10
*****


@iam2bam


View Profile WWW
« Reply #5 on: February 04, 2010, 07:21:34 AM »

It doesn't matter, just set the levelCenter.y somewhere else Smiley
Logged

Working on HeliBrawl
NandoSoft
Level 1
*



View Profile
« Reply #6 on: February 04, 2010, 12:29:27 PM »

Yes of course!!  Big Laff
Logged
NandoSoft
Level 1
*



View Profile
« Reply #7 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



« Last Edit: February 08, 2010, 05:15:18 AM by NandoSoft » Logged
Martin 2BAM
Level 10
*****


@iam2bam


View Profile WWW
« Reply #8 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.
Logged

Working on HeliBrawl
NandoSoft
Level 1
*



View Profile
« Reply #9 on: February 08, 2010, 11:27:12 AM »

thank you man  Beer!

ill post a video of how things are coming along
Logged
NandoSoft
Level 1
*



View Profile
« Reply #10 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++;
                        }
                    }
                }
Logged
Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #11 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:





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

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

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
pgil
Guest
« Reply #12 on: February 08, 2010, 03:38:14 PM »

The graphics are really too good for such a boring game.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic