I have trouble implementing the Smooth Scrolling module in an existing project

Started by Blondbraid, Thu 17/05/2018 10:11:25

Previous topic - Next topic

Blondbraid

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
 player.LockView(9);
 player.Animate(3,4,eOnce,eBlock);
 player.UnlockView();
 player.SetIdleView(0,0);

the game crashes and I get this message:

How do I make the script work and implement the smooth scrolling module in my existing AGS project?


Crimson Wizard

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

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

int loop;
if (targetCharacter.View == targetCharacter.NormalView)
    loop = targetCharacter.Loop;
else
    loop = 0;
TargetSprite = Game.GetViewFrame(targetCharacter.NormalView, loop, 0);

Blondbraid

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
  int TargetHeight = FloatToInt (IntToFloat(Game.SpriteHeight[TargetSprite.Graphic])*scaling);

And the error message says:
Error running function
`repeatedly_execute_always':
Error: Null pointer referenced


Crimson Wizard

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.

Blondbraid

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?


Crimson Wizard

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

Blondbraid

No working download link? Odd, the one at the top of the forum thread worked for me:
QuoteDownload: From Techtroupe.net

Anyway, I saw the example in your link, and I think I got it.
The version I downloaded used
Code: ags
targetCharacter = cEgo;

Thank yo for your help!


morganw

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.

SMF spam blocked by CleanTalk