Zoom in on a specific point with Tween module

Started by AndreasBlack, Thu 24/08/2023 02:44:00

Previous topic - Next topic

AndreasBlack

I can't seem to find any options for how to zoom in and have it zoom in at a certain X/Y on the screen ??? 
Looking at the Tween Git Manual something like this should be possible alltho the manual's example uses a GUI and i'm trying the Camera. My Camera.position does nothing in this room, but it works in another wider room, unsure why. Tried putting various x/y's, nothing happens. Atm i'm trying in afterfade.

Code: ags
Game.Camera.TweenPosition(2.0, 1, 300);
Game.Camera.TweenSize(2.5, 100, 100);



Thanks!

Crimson Wizard

#1
First of all, afaik Tweens are blocking by default, meaning they will act one by one and not simultaneously.
The first tween you call is Position, but in AGS cameras are currently clamped to the room bounds, meaning you cannot move the camera unless you make it smaller than the room first. This explains why position does not work.
You need to pass non-blocking as a parameter to them to make them act together.
Probably you also need to do "Game.Camera.AutoTracking = false;" to disable camera following the player first.



Besides that, if you intend to zoom in "centered" over certain position, then I don't think you will be able to reliably achieve this using Tweens, unless you calculate parameters very carefully, including timing.

The thing is that when you do a "centered" zoom, your position must stay strictly in sync with the size, but these two tweens in your code act separately unrelated to each other.

I guess this might be a good feature suggestion to edmundito for the next Tween release.

The idea is to calculate a camera position so that the zoom is done "towards" a certain point. You may call this point a "anchor point".
In the simplest case, for each moment of transition:
   camera.X = anchor_x - camera.Width / 2
   camera.Y = anchor_y - camera.Height / 2
but this will cause jumps in a larger rooms, so another algorithm is necessary... Unfortunately I don't remember this by heart, and don't have more spare time at the moment, but maybe somebody else will write this here.
Idk if this may be helpful, but we have this code in the Editor, for calculating new position when zooming into the room:
https://github.com/adventuregamestudio/ags/blob/master/Editor/AGS.Editor/Panes/Room/RoomSettingsEditor.cs#L1127-L1150

SMF spam blocked by CleanTalk