Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

Parallax?


Recommended Posts

Well, in general, you can simply set the position of a background object using something like:

background_x[ whatever] = view_xview[ 0] * 0.95;
background_y[ whatever] = view_yview[ 0] * 0.99;

However, the problem is that the view system gets changed just before it is used (which is just before backgrounds are drawn). And so there's no way you'll be able to change this value in time for an updated view. What you get is a jumpy background because it lags behind by one step.

The usual way to avoid this is to draw the background yourself in a high-depth object. But to do that with layered paralax, you're going to need some function to draw the background tiled only horizontally.

Link to comment
Share on other sites

Well, in general, you can simply set the position of a background object using something like:

background_x[ whatever] = view_xview[ 0] * 0.95;
background_y[ whatever] = view_yview[ 0] * 0.99;

However, the problem is that the view system gets changed just before it is used (which is just before backgrounds are drawn). And so there's no way you'll be able to change this value in time for an updated view. What you get is a jumpy background because it lags behind by one step.

The usual way to avoid this is to draw the background yourself in a high-depth object. But to do that with layered paralax, you're going to need some function to draw the background tiled only horizontally.

I've been experimenting, but it doesn't seem to work.

if (view_hspeed[0] > 0 or view_hspeed[0] < 0)
{background_hspeed[0] = (hsp*39/40)}
else
{background_hspeed[0] = 0}

I almost got it, too, but it won't work. It works by giving the background a speed equivalent to Neon's speed and multiplying it by 39/40. Generally, this comes out as a number close to 1. (Neon's maximum speed, by the way, IS 40, and therefore, when he's at his maximum speed, the background will barely keep up at 39. This may be a problem...)

I can't have the background move in the opposite direction; then, it looks like Neon is moving faster than he is.

When Neon's speed is 2, for example, the background will be moving slower, considering 78 > 40, thus we end up with about 1.09. So, the background SHOULD be moving WITH Neon, but moving slower than him, making it, in general, appear to be moving slower altogether.

But there's an error in it. For whatever reason, the code ignores the speed of the room and goes straight to Neon's speed(he's given a bit of room between the view's boundaries to follow). So, even if the view is NOT moving, the background is, and it looks messy.

I'm still trying to work things out, here, so... ANY help would be appreciated.

Link to comment
Share on other sites

What do you mean "doesn't seem to work"? Do you mind being more specific on what you tried and whether the nothing happened whatsoever or whether it was, in some way, off?

--

As for your method, the only way to fix the fact that it moves based on Neon's speed and not on the view's speed would be to make it based on the change in view (note view_hspeed means something else; namely how fast a view is capable of following an object). And that encounters the same problems as I mentioned before (namely that you can't update the background values in between the time the view variables update and the time the background is drawn).

Another problem with your method is that it will be off if Neon is moving on anything but a flat surface (angle = 0). That can easily be solved by saying, instead:

background_hspeed[0] = lengthdir_x( hsp*39/40, angle);

But you will still have the problems encountered before.

--

An alternative would be to disable the automatic view following and to update the view values yourself (note, this code will not have any in-between area; though it wouldn't be too hard to code some). This code should go in the End Step event, after Sonic/Neon has done all his moving but before he is drawn.

view_xview[0] = min( room_width, max( 0, x - view_wview[0]/2));
view_yview[0] = min( room_height, max( 0, y - view_hview[0]/2));

background_x[0] = view_xview[0]*0.975;

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...