Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: DiegoHolt on Tue 01/10/2024 17:52:59

Title: A little lag when the screen is scrolling
Post by: DiegoHolt on Tue 01/10/2024 17:52:59
Hello, beautiful community.

I'm having a debate with a friend here, and he's starting to convince me.

The thing is the scrolling, he says there is a little lag (I don't know what to call it, and 'lag' seems to be fair enough) when the screen scrolls. I didn't notice it before, but now I can't unseen it.

Is this normal? Maybe I needed to change something like the FPS when changing the game's resolution?


Thanks for your time!  :)
Title: Re: A little lag when the screen is scrolling
Post by: ThreeOhFour on Tue 01/10/2024 20:30:28
It's definitely not as smooth as it could be. Have you tried using the Tween module to move the camera? What command are you using to move the screen?
Title: Re: A little lag when the screen is scrolling
Post by: AndreasBlack on Tue 01/10/2024 20:33:35
set the framerate to 60fps or higher. I think AGS standard is 40, unless they've changed it. See if that helps
Title: Re: A little lag when the screen is scrolling
Post by: Khris on Tue 01/10/2024 20:47:25
Looks like you're using the player character for this. Walking characters usually do not move smooth because they do not have dozens of walkcycle frames and therefore will move a bunch of pixels every few frames. This will give a choppy result, which is why there are a bunch of modules that take care of this.
There's even a smooth scrolling module written specifically to address this very common issue: https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-smooth-scrolling-parallax-v1-7-1/
Title: Re: A little lag when the screen is scrolling
Post by: Danvzare on Wed 02/10/2024 12:38:55

It's an option that's set to true by default because it makes walking animations look decent with zero effort on the part of the artist or programmer.
But the cost can be jerky movement that is enough to give someone motion sickness in my opinion.
Title: Re: A little lag when the screen is scrolling
Post by: eri0o on Wed 02/10/2024 15:36:59
I have a script somewhere where I have a config so that if the screen can't move it uses Movement linked to animation and if can move it doesn't - by setting the property to false through script. I also use two frames per image when using Movement linked to animation, so it can "fake slide" something that looks like a half frame and this allows me using a small pixel distance per step, which is the main thing that causes choppiness.

In this particular scene shown in the video though, it looks like a simple camera tween would be the easy way to have it smooth - along with making sure you have SetGameSpeed(60) at game_start.
Title: Re: A little lag when the screen is scrolling
Post by: Crimson Wizard on Wed 02/10/2024 15:58:11
It's unfortunate that no code is posted, and I dislike guessing.

But since this was not mentioned in the replies above: if you are scrolling camera yourself in script, and target some character's or object's position, then make certain that it's done in "late_repeatedly_execute_always", this way it will be done *after* character moves.
Title: Re: A little lag when the screen is scrolling
Post by: Snarky on Wed 02/10/2024 16:04:04
Quote from: Danvzare on Wed 02/10/2024 12:38:55
  • Select the player character in the editor, and look at the list of options to the side.
  • There should be one option that says "MovementLinkedToAnimation", set it to "False".
  • Enjoy your smooth scrolling screen.

It's an option that's set to true by default because it makes walking animations look decent with zero effort on the part of the artist or programmer.
But the cost can be jerky movement that is enough to give someone motion sickness in my opinion.

I strongly disagree with this advice.

If you turn off "Movement linked to animation" you get a gliding effect when walking, since the character moves even when the animation frame doesn't change, making the feet slide across the ground. This looks very bad, and is a bigger issue than the scrolling, which can anyway be fixed in other ways.

And in this case it shouldn't have anything to do with the issue at all, since there is no walking character on the screen. The original poster must be doing something in a non-optimal way.
Title: Re: A little lag when the screen is scrolling
Post by: eri0o on Wed 02/10/2024 17:00:20
Right, the code for tween is something like

Game.Camera.TweenPosition(1.0 /*seconds*/, 1200 /*X*/, 0/*Y*/, eEaseLinear, eTweenBlock);
More info in the module docs https://edmundito.gitbook.io/ags-tween/basic/screen
Title: Re: A little lag when the screen is scrolling
Post by: Danvzare on Thu 03/10/2024 11:31:50
Quote from: Snarky on Wed 02/10/2024 16:04:04If you turn off "Movement linked to animation" you get a gliding effect when walking
Only when you set things up wrong.
But why take my word for it, when I can just provide a series of gifs.

This is what you get with MovementLinkedToAnimation is set to true, and it's set correctly:
(https://twentyquidamusements.thecomicstrip.org/files/ags/goodlinked.gif)

This is what you get with MovementLinkedToAnimation is set to true, and it's set wrong:
(https://twentyquidamusements.thecomicstrip.org/files/ags/badlinked.gif)

This is what you get with MovementLinkedToAnimation is set to false, and it's set correctly:
(https://twentyquidamusements.thecomicstrip.org/files/ags/goodnonlinked.gif)

This is what you get with MovementLinkedToAnimation is set to false, and it's set wrong:
(https://twentyquidamusements.thecomicstrip.org/files/ags/badnonlinked.gif)


As you can clearly see, setting it to false not only gives a much smoother scrolling effect and less choppy character movement, but when the character animation delay and speed are set correctly, it even removes the gliding effect that people like Snarky think MovementLinkedToAnimation is required to fix.
Title: Re: A little lag when the screen is scrolling
Post by: Crimson Wizard on Thu 03/10/2024 12:02:57
Quote from: Danvzare on Thu 03/10/2024 11:31:50As you can clearly see, setting it to false not only gives a much smoother scrolling effect

That is because camera is made to follow the character's position exactly in AGS by default, but that's not the perfect solution.
I suppose that If camera were scripted to move with the average character speed instead, then it would not depend on MovementLinkedToAnimation at all; as it should be.

EDIT: unfortunately, it may not be trivial to do in script in case of randomly walking character, as character "velocity" (or movement direction) is not exposed to script at the moment. The script would have to keep track on character positions and do projection.
Title: Re: A little lag when the screen is scrolling
Post by: Snarky on Thu 03/10/2024 14:01:02
Quote from: Danvzare on Thu 03/10/2024 11:31:50This is what you get with MovementLinkedToAnimation is set to false, and it's set correctly:
(https://twentyquidamusements.thecomicstrip.org/files/ags/goodnonlinked.gif)

As you can clearly see, setting it to false not only gives a much smoother scrolling effect and less choppy character movement, but when the character animation delay and speed are set correctly, it even removes the gliding effect that people like Snarky think MovementLinkedToAnimation is required to fix.

Do you not see the feet gliding in this gif? He's practically moonwalking!
Title: Re: A little lag when the screen is scrolling
Post by: ThreeOhFour on Thu 03/10/2024 14:50:58
Danvzare, it can be a little hard to see these things if you're not looking close enough, but it might be worth slowing your gifs down and zooming in and taking a closer look. This is how your "goodnonlinked.gif" example appears when you do that:

(https://i.imgur.com/zXbWg88.gif)
Title: Re: A little lag when the screen is scrolling
Post by: Danvzare on Thu 03/10/2024 18:10:24
I suppose we'll just have to agree to disagree.  (nod)

I prefer the way the vast majority of 2D games handle walk cycles.
And you prefer the way old PC games handled walk cycles.

We're both biased in our preferences. And if you believe otherwise, try showing the goodnonlinked and goodlinked gifs to any non-adventure game fan and simply ask which they prefer (without explaining what the difference is).
Heck, just show them the part of the gifs before the room starts scrolling, for maximum objectivity. I think you'll find this so-called "gliding" to be preferable to choppy animation for most people. But then again, I could be wrong. I can only attest to the opinion of the few people I've shown those gifs to.
But it does seem to me as though the false consensus effect is strong with regards to this.  (nod)
Title: Re: A little lag when the screen is scrolling
Post by: ThreeOhFour on Thu 03/10/2024 18:14:10
Quote from: Danvzare on Thu 03/10/2024 11:31:50it even removes the gliding effect that people like Snarky think MovementLinkedToAnimation is required to fix.

Preference is fine, everybody's taste is different. Just pointing out that this claim you made was incorrect.
Title: Re: A little lag when the screen is scrolling
Post by: DiegoHolt on Thu 03/10/2024 18:15:58
Thanks to all of you for taking your time to reply.

And sorry for not posting any code! I guess I assumed everyone would know that I'm a rookie and my scripting is absolutely basic.

In the video I've posted, I'm using the player walking with transparency = 100

Now I've tried using some modules (rellax and smooth scroll) and setting to false MovementLinkedToAnimation, but now I'm getting side effects beacuse the screen lag is corrected but the walking animation is showing some issues. With the rellax module, my character looks kind of ghostly when the screen is scrolling. And with MovementLinkedToAnimation set to false, there is a little glitch when walking on the Y axis (up and down)

I'll post some videos later to show you what I mean.

Again, thank you all for sharing your knowledge and time!  :-D
Title: Re: A little lag when the screen is scrolling
Post by: Crimson Wizard on Thu 03/10/2024 18:45:43
Quote from: DiegoHolt on Thu 03/10/2024 18:15:58And sorry for not posting any code! I guess I assumed everyone would know that I'm a rookie and my scripting is absolutely basic.

In the video I've posted, I'm using the player walking with transparency = 100

Right, it's always essential to clarify how the behavior was achieved, because it cannot be obvious from the video: as visibly similar result may be achieved in a large number of ways.
For instance, I had no idea that you have a invisible player there, but I knew that it's potentially possible to make camera follow invisible character using a script, that's why I added a note about "late_repeatedly_execute.." (but since you are using builtin camera movement, that is not applicable, unless you script a custom one).
Title: Re: A little lag when the screen is scrolling
Post by: DiegoHolt on Fri 04/10/2024 00:48:05
@Crimson Wizard actually I'm even more basic than that, because I didn't use any script for the camera to follow the invisible character. I just tried it and it worked. By the way, that character is the player.

Now I'm using the Tween module to move the camera, so that lag thing is covered. But I still see it when the player is walking. Any help there, please?
Title: Re: A little lag when the screen is scrolling
Post by: eri0o on Fri 04/10/2024 03:03:00
Under the spoiler I hid a general explanation for rellax

Spoiler
If the character has movement linked to animation it will teleport the speed amount of pixels, then wait the delay of the frame, and then teleport again such amount of pixels that is set in the speed, which gives the perception that the character walks when it animates.

Rellax uses two different things to follow the player (I am going from my memory of my code...):

  • If the player is moving, it uses some lerp approach to interactively approach the actual camera target, which smooths it out
  • If the player is not moving, it will instead tween the camera to where it should be - this allows the camera to properly "lock" into target

If the player is walking very fast, the lerping approach will make the character ghost as the camera tries to catch-up with the player - if it's full scrolling, the camera is trying to keep the character in center. There are a few additional nuances in rellax but this is sort of the gist of it all.

I haven't been able to properly devise any way that it doesn't look so, but if the game is higher resolution and the character doesn't use movement linked to animation this is usually less perceptual.

The only way I think this could actually function is with floats for camera movement - this would allow the camera to position in fractions of pixels.
[close]

In actual games I have been able to workout the camera smoothing in a case by case basis, to avoid ghosting and all that, if you could show a video of the room where you are facing issue we could share ideas - one example, make areas and have the camera tween between areas when the player reach specific thresholds, but there are several approaches, you can even use tween+camera api to zoom out and zoom in.
Title: Re: A little lag when the screen is scrolling
Post by: Khris on Fri 04/10/2024 09:26:40
You were dealing with a cutscene, so the tween module took care of that. During the game, the original issue is again what's causing this. The solution is again the SmoothScrolling module, which simply fixes the scrolling of the room being directly tied to the player's x coordinate and therefore being choppy.
I want to point out that in my very first reply over two days ago I correctly identified the cause of the issue and already posted a working solution (a link to the module) that fixes both the original issue and the current one.
Title: Re: A little lag when the screen is scrolling
Post by: DiegoHolt on Fri 04/10/2024 18:20:11
@Khris I did try that module, but after creating the properties I'm getting this error message:

Smooth Scrolling & Parallax.asc(305): Error (line 305): undefined symbol 'GetViewportX'

This are the code lines, and I'm guessing the next one will give an error as well:

int viewx = GetViewportX();

int viewy = GetViewportY();
Title: Re: A little lag when the screen is scrolling
Post by: Crimson Wizard on Fri 04/10/2024 18:26:43
Quote from: DiegoHolt on Fri 04/10/2024 18:20:11Smooth Scrolling & Parallax.asc(305): Error (line 305): undefined symbol 'GetViewportX'

This are the code lines, and I'm guessing the next one will give an error as well:

int viewx = GetViewportX();

int viewy = GetViewportY();

Either:
1. Set "Script compatibility level" to 3.4.* (in General Settings)
2. Replace by Game.Camera.X, Game.Camera.Y respectively.

Where to find replacements for deprecated functions:
https://adventuregamestudio.github.io/ags-manual/ObsoleteScriptAPI.html
Title: Re: A little lag when the screen is scrolling
Post by: DiegoHolt on Fri 04/10/2024 18:32:11
Thanks for the quick answer, @Crimson Wizard

I've changed to Game.Camera but now I'm getting this error:

Smooth Scrolling & Parallax.asc(556): Error (line 556): '.ViewportWidth' is not a public member of 'System'. Are you sure you spelt it correctly (remember, capital letters are important)?

This is the line:

PxObjOriginX[NumberObj] = object[objectpass].X + FloatToInt((IntToFloat(object[objectpass].X)/IntToFloat(Room.Width))*(IntToFloat(Room.Width-System.ViewportWidth)*3.0));
I haven't tried the script compatibility because I don't know where to do that.
Title: Re: A little lag when the screen is scrolling
Post by: Crimson Wizard on Fri 04/10/2024 19:07:54
Quote from: DiegoHolt on Fri 04/10/2024 18:32:11Smooth Scrolling & Parallax.asc(556): Error (line 556): '.ViewportWidth' is not a public member of 'System'. Are you sure you spelt it correctly (remember, capital letters are important)?

This is a similar problem.
https://adventuregamestudio.github.io/ags-manual/ObsoleteScriptAPI.html

System.ViewportHeight  --->   Screen.Height
System.ViewportWidth  --->   Screen.Width

Quote from: DiegoHolt on Fri 04/10/2024 18:32:11I haven't tried the script compatibility because I don't know where to do that.

It's in General Settings:
https://adventuregamestudio.github.io/ags-manual/GeneralSettings.html#backwards-compatibility