Author Topic: MODULE: Smooth Scrolling & Parallax v1.7.1  (Read 48424 times)

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
 
Quote
Sorry for digging up, but I'm having issues for controlling the smooth scrolling, and I thought that the answer could be beneficial to everyone, that's why I'm posting here instead of PM'ing.

First I'd like to say that this module is really sweet. It's a neat effect, and it was made without relying on the Tween module -- that's a cool achievement, technically speaking.

My issue : (I'm detailing steps to reproduce it)
- Create a 320x200 game
- Create a 600x220 room (it's slightly higher than the viewport's height)
- Bring your main character in it, let's say at (50,100).
- Create a dummy character (I'll call it cCamera) which uses a transparent sprite. This one will be used to control the viewport.
- Also bring it into the room, at (1,219). <-- you agree with me that it's at the very bottom of the room.
- In the room script, call

Code: Adventure Game Studio
  1.   SmoothScroll_SetTargetCharacter(cCamera);
  2.   SmoothScroll_ScrollingOn();

What should happen: The viewport should move down and "stick" to the bottom of the room.
What happens: The viewport stays stuck at the top of the room.

I've run tests :
- the issue does not happen when the script moves cCamera left or right: the camera scrolls left and right accordingly.
- I thought it might come from "EdgeY" (defined in the module) so I moved cCamera far down : cCamera.y=400; but it didn't hemp.

What am I doing wrong?


EDIT: this is a tiny bug that Ali explains below. You will experience it only if you make a low-resolution game AND the camera needs to make only a small move (for example, it the room is only slightly larger than the viewport. For example your room is 32x220 and your game is 320x200). It's easily worked around with the solution given by Ali.
« Last Edit: 05 Dec 2014, 13:38 by Monsieur OUXX »
 

Ali

  • What will become of the baron?
    • Ali worked on a game that was nominated for an AGS Award!
      Ali worked on a game that won an AGS Award!
Hmm, I can't reproduce that following your instructions and using the version from the first post. The camera scrolls down to the bottom (actually it ends up 1 pixel short of the bottom, to avoid a clunky stop. This is intentional but perhaps not desirable for low-res games.)

The only thing I'm not sure of is why you're using SmoothScroll_SetTargetCharacter(cCamera). Is that your own function? I had to use targetCharacter = cCamera; in its place.

Also, the only reason this doesn't use the Tween Module is that it didn't exist when I started writing it!


Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
The only thing I'm not sure of is why you're using SmoothScroll_SetTargetCharacter(cCamera). Is that your own function? I had to use targetCharacter = cCamera; in its place.
Silly me, I forgot to mention I added that function. That's the only change I made to the module, it does exactly targetCharacter = cCamera; (I just don't like global variables floating around, that's an OCD thing).
Hmmmm, if you say you can't reproduce it, I'm in trouble. I hope there's no other call to one of your module's functions somewhere else in my gigantic code. I'll investigate more and come back.
« Last Edit: 03 Dec 2014, 15:14 by Monsieur OUXX »
 

Ali

  • What will become of the baron?
    • Ali worked on a game that was nominated for an AGS Award!
      Ali worked on a game that won an AGS Award!
Monsieur OUXX has found a bug which affects low res games with rooms only slightly larger than the viewport. Until I update the module, you can fix this problem by changing the 0.7s to 0.3s in whichever of these lines corresponds to the direction in which the screen is reluctant to scroll:

if (Centring == false && ScrollSpeedX < 0.7 && ScrollSpeedX > -0.7) ScrollSpeedX = 0.0;

if (Centring == false && ScrollSpeedY < 0.7 && ScrollSpeedY > -0.7) ScrollSpeedY = 0.0;

Hi guys,

Sorry if this has a very obvious answer or has been addressed before, but I can't find a reference to it. In the game I'm working on, the screen can scroll up and down as well as left and right. Is it possible to fix the Y pos of an object that is being used under PxPOS. I need them to parallax left and right, but not up and down. Does that make sense? Any help much appreciated!

UPDATE: I FOUND THE SOLUTION :D

Shaun
« Last Edit: 09 Dec 2014, 16:44 by shaun9991 »
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

Re: MODULE: Smooth Scrolling & Parallax v1.7.1
« Reply #165 on: 23 Jun 2018, 15:47 »
Hey! I love the smoothscroll + parallax module! It's really awesome!

But I find myself in need of more layers for the background to make things work prettier... Has someone ever added layers ?

I would need something like 25%, 33%, 50%, 66%, 75%, to go from a static (but animated scrolling) sky, to each layer until the front layer...


Ali

  • What will become of the baron?
    • Ali worked on a game that was nominated for an AGS Award!
      Ali worked on a game that won an AGS Award!
Re: MODULE: Smooth Scrolling & Parallax v1.7.1
« Reply #166 on: 23 Jun 2018, 16:29 »
I haven't got any plans to add more layers, not least because it would break existing games that use the module. But if you want a more subtle effect, you can play round with the maths in this section:

Code: Adventure Game Studio
  1. if (PxObj[objectpass].GetProperty("PxPos")==7) {
  2.  
  3.       PxObj[objectpass].X=PxObjOriginX[objectpass]-FloatToInt(IntToFloat(viewx)*3.0); //Move the object in opposite direction to the screen scrolling, at 150% of the scrolling speed.
  4.  
  5.       PxObj[objectpass].Y=PxObjOriginY[objectpass]-FloatToInt(IntToFloat(viewy)*3.0);
  6.    
  7.     }

Down to...

Code: Adventure Game Studio
  1. else if (PxObj[objectpass].GetProperty("PxPos")==1) {
  2.      
  3.       PxObj[objectpass].X=PxObjOriginX[objectpass]-FloatToInt(IntToFloat(viewx)/4.0); //Move the object in opposite direction to the screen scrolling, at a quarter of the speed of the scrolling.
  4.  
  5.       PxObj[objectpass].Y=PxObjOriginY[objectpass]-FloatToInt(IntToFloat(viewy)/4.0);
  6.  

So to make them move more subtly, you could change /4.0 to /16.0 for PxPos 1, and so on.

I probably should break those values out into floats, so you can change them from the script. I might do that in a future update, but for now I'm afraid it's up to you to experiment until you get a speed you like.

Re: MODULE: Smooth Scrolling & Parallax v1.7.1
« Reply #167 on: 23 Jun 2018, 17:28 »
the positive 7 to 1 are intended for the foreground object, correct ? I think I found the code for the negatives and made the like:

-1 25% (1.0/4.0)
-2 33% (1.0/3.0)
-3 40% (2.0/5.0)
-4 50% (1.0/2.0)
-5 66% (2.0/3.0)
-6 75% (3.0/4.0)
[nothing]  100%  (is this understanding correct?)
-7 0%

I edited accordingly the code for the positioning too - I replicated the fractions.

I am trying to create more layers in the background (now there are only two -1, and -2), but I am having a hard time making them transit from the foreground layer. Imagine like a tiny plains in the background, to achieve something like the line scrolling Street Fighter 2 uses on the ground, but instead on the distant space...

The idea was to apply in this background example video here . the failed lines.

I can open a topic in the technical forum if it's better.
« Last Edit: 23 Jun 2018, 17:30 by eri0o »

Ali

  • What will become of the baron?
    • Ali worked on a game that was nominated for an AGS Award!
      Ali worked on a game that won an AGS Award!
Re: MODULE: Smooth Scrolling & Parallax v1.7.1
« Reply #168 on: 23 Jun 2018, 17:34 »
Sorry, I forgot to mention the positioning! Yes, those are for foreground objects. There's nothing to stop you replacing that whole section with different mutlipliers to create incrementally different parallax layers. I'd be worried about having too many large objects in a room, in terms of performance. But these days, that's much less of an issue.

Re: MODULE: Smooth Scrolling & Parallax v1.7.1
« Reply #169 on: 23 Jun 2018, 18:02 »
Code: Adventure Game Studio
  1.     else if (PxObj[objectpass].GetProperty("PxPos")==-7) {
  2.       PxObj[objectpass].X=PxObjOriginX[objectpass] + viewx; //Keep the object in the same place relative to the screen during scrolling.
  3.       PxObj[objectpass].Y=PxObjOriginY[objectpass] + viewy;
  4.       }
  5.  

Ok, looking through the code, if this is the code to keep the object in the same position, I expect the closer viewx and viewy are from zero, the more anchored is the object to the room bg itself, and so my previous understanding of the fraction was wrong.

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: MODULE: Smooth Scrolling & Parallax v1.7.1
« Reply #170 on: 26 Jun 2018, 14:02 »
Coincidence : I also need to post a question about this module right now. Let me know if it interferes with the other conversation.

Add spoiler tag for Hidden:
I'm trying to set up "edges" to the smooth scrolling. What I mean is this : imagine you're in a room that's 600x600. You set up "edges" like this: (Left=100, right = 500, top=100, bottom=500). That's a 400x400 area.
- I want that no matter where the character walks, the viewport never exits that area.
- However when the player character is within that area, then the smooth scrolling follows it normally.

How would I achieve that?
EDIT: I'm in the process of succeeding.
Well I'm not :(
« Last Edit: 26 Jun 2018, 22:36 by Monsieur OUXX »
 

Ali

  • What will become of the baron?
    • Ali worked on a game that was nominated for an AGS Award!
      Ali worked on a game that won an AGS Award!
Re: MODULE: Smooth Scrolling & Parallax v1.7.1
« Reply #171 on: 26 Jun 2018, 14:19 »
For the record, eri0o and I moved to DMs, and then he modified the module himself to serve his needs. I didn't abandon him!

To create edges, rather than modify the module, I would have a dummy character pinned to the X and Y of the player as long as they are within the prescribed limits. If they leave the prescribed limits, the dummy stops following and the target character switches to the dummy. Maybe?

Edit: In fact, the target character could always be the dummy, no need to switch.
« Last Edit: 26 Jun 2018, 19:46 by Ali »

Re: MODULE: Smooth Scrolling & Parallax v1.7.1
« Reply #172 on: 26 Jun 2018, 15:20 »
Ali went to pick cigarettes and never returned.

Edit: Ali idea is pretty good, on repeatedly execute always of the room, make a dummy invisible character be at same x & y of player character IF within the bounds, and do nothing if not (this will make the character not move in certain places). Use SmoothScroll's targetCharacter, and do targetCharacter=cDummy.
« Last Edit: 27 Jun 2018, 04:45 by eri0o »

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: MODULE: Smooth Scrolling & Parallax v1.7.1
« Reply #173 on: 26 Jun 2018, 22:37 »
I thought I was understanding the script, but I don't. Too many coordinates transformations for my little brain. Anyone could put me in the right direction to add arbitrary edges within the room that lock the scrolling, in replacement of ((0,0), (Room.Width, Room.Height)) ? I don't care if that breaks the parallax, I just need to block the scrolling beyond those edges.

EDIT : I got tired of (failing) to do it elegantly, so instead I went brute force, like this :

Code: Adventure Game Studio
  1.         //COMMENTED OUT
  2.         //SetViewport(FloatToInt(ScreenCentreX, eRoundDown) - HalfScreenWidth, FloatToInt(ScreenCentreY, eRoundDown) - HalfScreenHeight); // Set the Viewport position relative to ScreenCentreX and Y.  
  3.  
  4.         //NEW SCRIPT
  5.         int x = FloatToInt(ScreenCentreX, eRoundDown) - HalfScreenWidth;
  6.         int y = FloatToInt(ScreenCentreY, eRoundDown) - HalfScreenHeight;
  7.        
  8.         if (x<edgeLeft)
  9.             x = edgeLeft;
  10.         else if (x+System.ViewportWidth > edgeRight)
  11.             x = edgeRight-System.ViewportWidth;
  12.        
  13.  
  14.         if (y<edgeTop)
  15.             y = edgeTop;
  16.         else if (y+System.ViewportHeight > edgeBottom)
  17.             y = edgeBottom-System.ViewportHeight;
  18.        
  19.        
  20.         SetViewport(x, y);
  21.  
  22.  
The scrolling doesn't stop as smoothly when the player reachs the edges, but it totally fools the eye for someone who's not seen the original smoothness.
« Last Edit: 26 Jun 2018, 23:02 by Monsieur OUXX »