• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Desynchronized parallax scrolling problem

D

Drago Supremo

Guest
Hi everyone,
i tried to add a simple parallax scrolling effect to my platform by this code found on a tutorial.
Object: obj_parallax
Create Event:
Code:
///Sets the Parallax Factor

parallax[0] = 0;

for (i = 0; background_visible[i]; i++)

{

  parallax[0] = background_x[i] / 100;

}
Step Event:
Code:
///Makes The Parallax Effect
for (i = 0; background_visible[i]; i++)
{
  background_x = parallax [i] * view_xview;
}
Now the problem i suppose is that in the tutorial the camera moved in a simple way in the Step Event above so that the camera moved before the parallax effect and the last one was perfectly synchronized, while i'm using all the functions in the Views section in my room settings so that the parallax effect sets before the camera movement (because if i'm not wrong the camera movement take place after all step events),
getting an initial delay effect when the camera starts to move or stop because in the first and last frames the Step in parallax is still using the previous frame's view_xview value.

I tried to fix this changing the Step Event into a Draw Event, but this doesn't look like a an efficient solution considering also that the obj_parallax should set invisble and that anyway this didn't work.

I hope i explained myself sufficiently well and thank's in advance for the help.
 
D

Drago Supremo

Guest
The delay is indeed because your view moves after. Make the view move and then calculate where the backgrounds should be in relation to it.
So by this way i should move the view by code in the Step Event? Or there is an event the performs after the view movement?
 
D

Drago Supremo

Guest
So by this way i should move the view by code in the Step Event? Or there is an event the performs after the view movement?
It seems to work managing the view in my Player object immediately after moving the Player in its Step Event by this code:
Code:
 //Sets the view borders
  leftBorderAxis = view_xview + view_hborder;
  rightBorderAxis = view_xview + view_wview - view_hborder;
 
  //Calculates player's relative position to the borders
  difLeft = x - leftBorderAxis;   //Touches the left border if value -hborder<difLeft<0
  difRight = x + view_wview - rightBorderAxis;  //Touches the left border if value 0<difLeft<hborder
 
  //Sets the view's speed if player's direction and the touching border coincide
  if ((difLeft < 0) and (sign(difLeft) == sign(hsp))) or ((difLeft > 0) and (sign(difRight) == sign(hsp))) viewHoSpeed = hsp else viewHoSpeed = 0;
 
  //Checks if the view is about to exit the room and moves it to the edge
  if (view_xview + viewHoSpeed < 0) or (view_xview + view_wview + viewHoSpeed > room_width)
  {
    while !(view_xview + viewHoSpeed < 0) and !(view_xview + view_wview + viewHoSpeed > room_width) view_xview += sign(viewHoSpeed)
    viewHoSpeed = 0;
  }
 
  //Moves the view
 view_xview += viewHoSpeed;
Do you think is a quite efficient script or there is an easier and more efficient way to manage views?
 
Top