Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Blondbraid on Thu 17/05/2018 10:11:25

Title: I have trouble implementing the Smooth Scrolling module in an existing project
Post by: Blondbraid on Thu 17/05/2018 10:11:25
Hi, I tried to import this Smooth scrolling module (http://www.adventuregamestudio.co.uk/forums/index.php?topic=33142.0) into an AGS project, but the game keeps crashing during the intro cutscene I've programmed,
every time the dialogue script reaches this command:
Code (ags) Select
player.LockView(9);
player.Animate(3,4,eOnce,eBlock);
player.UnlockView();
player.SetIdleView(0,0);

the game crashes and I get this message:
(https://i.imgur.com/BcAiNsD.png)
How do I make the script work and implement the smooth scrolling module in my existing AGS project?
Title: Re: I have trouble implementing the Smooth Scrolling module in an existing project
Post by: Crimson Wizard on Thu 17/05/2018 10:23:22
This seem to be a mistake to always use NormalView finding character's height. As in your example, you may be playing some animation at this time, and Character.Loop may be a loop from another view.

You probably need to use this instead:
Code (ags) Select

Game.GetViewFrame(targetCharacter.View, targetCharacter.Loop, targetCharacter.Frame);

This way it should always get actual frame.

EDIT:

Hmm, on the other hand, maybe they have a reasoning of keeping camera centered to the NormalView for consistency reasons to prevent camera jumps. In such case, it is perhaps necessary to find the loop number depending on where character is facing to. Unfortunately, characters do not have a distinct facing property (it is usually found from the loop itself).

One trivial solution that comes to mind:
Code (ags) Select

int loop;
if (targetCharacter.View == targetCharacter.NormalView)
    loop = targetCharacter.Loop;
else
    loop = 0;
TargetSprite = Game.GetViewFrame(targetCharacter.NormalView, loop, 0);
Title: Re: I have trouble implementing the Smooth Scrolling module in an existing project
Post by: Blondbraid on Thu 17/05/2018 10:29:55
I tried replacing the highlighted line of code with the one you suggested, but now the game crashes on start
and this line of code is highlighted instead:
Code (ags) Select
  int TargetHeight = FloatToInt (IntToFloat(Game.SpriteHeight[TargetSprite.Graphic])*scaling);
And the error message says:
Error running function
`repeatedly_execute_always':
Error: Null pointer referenced
Title: Re: I have trouble implementing the Smooth Scrolling module in an existing project
Post by: Crimson Wizard on Thu 17/05/2018 10:31:40
Can you show an actual line which you replaced?

The code I posted was not a full line, but a part of it.

It should still be "TargetSprite = ..." of course.
Title: Re: I have trouble implementing the Smooth Scrolling module in an existing project
Post by: Blondbraid on Thu 17/05/2018 10:54:03
OK, I forgot to add the "TargetSprite = ..." in the beginning, that's why it didn't work.
The line I replaced was the one highlighted in yellow in my first screenshot, but when I added the "TargetSprite = ..." to the line I replaced it started working.

However, I've noticed another problem in the game. At one point, the player switches character for another cutscene, yet the camera is still centered on the first player character. Is there a way to control which character the camera is centered on?

The smooth scrolling module is also slowing the game down a bit, is there a way to shut off the script when the player is in a room without scrolling backgrounds?
Title: Re: I have trouble implementing the Smooth Scrolling module in an existing project
Post by: Crimson Wizard on Thu 17/05/2018 13:18:46
Quote from: Blondbraid on Thu 17/05/2018 10:54:03
However, I've noticed another problem in the game. At one point, the player switches character for another cutscene, yet the camera is still centered on the first player character. Is there a way to control which character the camera is centered on?

I cannot find working download link, so all can do is guess.
In the module thread, there is a line:
Quote
Module History:

v1.7 - Added targetCharacter pointer to make camera animation possible without switching player characters.

Maybe you just set targetCharacter? Or there is a function with name like "SetTargetCharacter".

EDIT: Here seem to be an example in this post:
http://www.adventuregamestudio.co.uk/forums/index.php?topic=33142.msg636501742#msg636501742
Title: Re: I have trouble implementing the Smooth Scrolling module in an existing project
Post by: Blondbraid on Thu 17/05/2018 16:25:35
No working download link? Odd, the one at the top of the forum thread worked for me:
QuoteDownload: From Techtroupe.net (http://techtroupe.net/content/Ali/smooth_scroll_1_7.zip)

Anyway, I saw the example in your link, and I think I got it.
The version I downloaded used
Code (ags) Select
targetCharacter = cEgo;
Thank yo for your help!
Title: Re: I have trouble implementing the Smooth Scrolling module in an existing project
Post by: morganw on Fri 18/05/2018 21:25:24
I just had the same problem, but it was because the direction I chose from the auto-complete list was eDirectionDownRight, when I actually wanted eDirectionRight. So the loop number was always invalid, as I have no view/loop for facing diagonally.