MODULE: Smooth Scrolling & Parallax v1.7.1

Started by Ali, Fri 07/12/2007 21:14:09

Previous topic - Next topic

Monsieur OUXX

#160
 
QuoteSorry 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: ags
  SmoothScroll_SetTargetCharacter(cCamera);
  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.
 

Ali

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

#162
Quote from: Ali on Wed 03/12/2014 09:38:37
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.
 

Ali

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;

shaun9991

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
Support Cloak and Dagger Games on Patreon: https://www.patreon.com/user?u=460039

eri0o

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

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: ags
if (PxObj[objectpass].GetProperty("PxPos")==7) {

      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.

      PxObj[objectpass].Y=PxObjOriginY[objectpass]-FloatToInt(IntToFloat(viewy)*3.0); 
    
    }


Down to...

Code: ags
else if (PxObj[objectpass].GetProperty("PxPos")==1) {
      
      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.

      PxObj[objectpass].Y=PxObjOriginY[objectpass]-FloatToInt(IntToFloat(viewy)/4.0); 


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.

eri0o

#167
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.

Ali

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.

eri0o

Code: ags

    else if (PxObj[objectpass].GetProperty("PxPos")==-7) {
      PxObj[objectpass].X=PxObjOriginX[objectpass] + viewx; //Keep the object in the same place relative to the screen during scrolling.
      PxObj[objectpass].Y=PxObjOriginY[objectpass] + viewy;
      }


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

#170
Coincidence : I also need to post a question about this module right now. Let me know if it interferes with the other conversation.

Spoiler

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?
[close]
EDIT: I'm in the process of succeeding.
Well I'm not :(
 

Ali

#171
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.

eri0o

#172
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.

Monsieur OUXX

#173
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: ags

        //COMMENTED OUT
        //SetViewport(FloatToInt(ScreenCentreX, eRoundDown) - HalfScreenWidth, FloatToInt(ScreenCentreY, eRoundDown) - HalfScreenHeight); // Set the Viewport position relative to ScreenCentreX and Y.  

        //NEW SCRIPT
        int x = FloatToInt(ScreenCentreX, eRoundDown) - HalfScreenWidth;
        int y = FloatToInt(ScreenCentreY, eRoundDown) - HalfScreenHeight;
        
        if (x<edgeLeft)
            x = edgeLeft;
        else if (x+System.ViewportWidth > edgeRight)
            x = edgeRight-System.ViewportWidth;
        

        if (y<edgeTop)
            y = edgeTop;
        else if (y+System.ViewportHeight > edgeBottom)
            y = edgeBottom-System.ViewportHeight;
        
        
        SetViewport(x, y);


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.
 

Hiboy_Luky

#174
Hello, My game crashes whenever my character enters idle animation and the game says the problem is in function GetTargetHeight on the line which begins with TargetSprite. Do you have any ideas what could be the problem? EDIT: actually the errors are on lines 521 and 912 and the error says: GetGameParameter: invalid frame specified so i just commented line 912 and 913 but i feel like there should be another way.

Ali

Does your idle animation have frames in all 4 directions?


Ali

In that case, put the same frame in the other 3 and it should work. (I think you risk AGS crashing anyway, unless the character is permanently locked in one direction.)


vga256

Hi Ali! I'm porting (Chicky's) Guard Duty to Linux and Mac, and I noticed that I cannot seem to get targetCharacter to work in Linux. The exact same code works fine in Mac and Windows, but for some reason Linux seems to be completely ignoring targetCharacter? I've included some videos to document the behaviour -- I was hoping you might be able to point me in the right direction!

The Linux and Mac ports are using v3.4.15 of the AGS interpreter. In Linux we're using Allegro 4.4.3 - the latest version of Allegro (just released a month ago), and an OpenGL renderer. Morganw also tested this out with the Software renderer, just in case OpenGL was causing the problem, and the same problem occurred with software rendering as well.

Some sample videos of what we're seeing:
Expected behaviour (Mac OS X): Camera pans down to knight when mouse hovers at bottom of screen.
Unexpected behaviour (Linux/Ubuntu): Mouse hovers at bottom of screen, and camera does not pan.
Another sample from a different part of the room:
Expected behaviour (Mac OS X): Camera pans down to knight, and you can use the ladder on the knight.
Unexpected behaviour (Linux/Ubuntu): Mouse hovers at the hotspot, but the camera doesn't pan to the knight.

Are there Linux-specific settings that need to be used, or have we missed something coding the scene to make it work in Linux? Chicky's project is using v1.7 of the module.

Thanks so much.

SMF spam blocked by CleanTalk