Character speech text doesn't adjust position for zoomed in viewport

Started by Intangible, Sat 22/04/2023 21:15:39

Previous topic - Next topic

Intangible

I have an AGS game that runs 800x600 resolution. At one point in a cutscene, I wanted to have the game's camera zoom in on a character who's talking. So, I did this:

Code: ags
    // Create the camera/viewport
    Camera* sceneCamera = Camera.Create();
    sceneCamera.SetSize(400, 300); // half the normal resolution = 2x zoom
    sceneCamera.AutoTracking = false;
    
    Viewport* sceneViewport = Viewport.Create();
    sceneViewport.Camera = sceneCamera;
    sceneCamera.SetAt(401, 326); // specific position of zoom on original screen
    
    // Do some stuff while zoomed in
    Wait(10);
    cTom.Say("Test dialog!");
    
    // Restore to original zoom
    sceneViewport.Delete();
    sceneCamera.Delete();

When the scene zooms in, the overall graphics behave as expected, but Tom's speech text doesn't appear above his character: instead, it appears at the location where Tom was originally shown on the screen, before the zoom-in. It seems that the character text doesn't adjust its position for the zoomed-in viewport.

Has anyone else seen this? Am I using cameras/viewports wrong?

Thanks in advance!

Crimson Wizard

#1
Hmm... if I remember correctly, the speech is always displayed in relation to the first visible viewport/camera pair. So if your primary viewport is still on the screen, the it will be displayed in its coordinates.

EDIT: OR, the first viewport where character is visible.

Note that its considered to be "visible" even if there's another viewport overlaying it. You'd have to disable it by setting Screen.Viewport.Visible = false temporarily.

But, if you do not need original camera to be seen at this time, then you do not have to create new viewport/camera pair, and may adjust existing ones instead. They are accessible as Screen.Viewport and Game.Camera.

I recall this was an issue before because the manual had examples with unnecessary camera creations, so people copied them. These examples were changed since:
https://adventuregamestudio.github.io/ags-manual/Camera.html
https://adventuregamestudio.github.io/ags-manual/Viewport.html

Intangible

Nice! Your feedback was right on the money... as soon as I changed my code to modify the existing Game camera, it worked fine. I don't even need to touch the viewport now:

Code: ags
    // Update the camera/viewport
    Game.Camera.SetSize(400, 300); // half the normal resolution = 2x zoom
    Game.Camera.SetAt(401, 326); // specific position of zoom on original screen
    Game.Camera.AutoTracking = false;
    
    // Do some stuff while zoomed in
    Wait(10);
    cTom.Say("Test dialog!");
    
    // Restore to original camera
    Game.Camera.SetSize(800, 600);
    Game.Camera.SetAt(0, 0);
    Game.Camera.AutoTracking = true;

Thanks for the quick answers!

SMF spam blocked by CleanTalk