Custom Camera.AutoTracking

Started by Sakspapir, Tue 27/06/2023 14:18:04

Previous topic - Next topic

Sakspapir

Hi guys,

In my game, one of the rooms is a lot larger than the Camera Size, so that when the player moves around (Camera.AutoTracking == true) then the camera follows the player.

When the playe moves "up" in the room, the camera still follows, but the camera is positioned in a way that the player is always at the top of the screen.

What I want to do is to make the camera follow the player (as it does) but the player should be positioned "lower" on the screen.


I've tried to put the following code in the room's "Room_RepExec()"-function:

Code: ags
Game.Camera.SetAt(cPlayer.x - 300, cPlayer.y - 200);

This kind of works, but there is a "shaking" in the picture. Im assuming there is an issue with the order of which the drawing functions are called.

Need help, and thanks in advance!

Crimson Wizard

Quote from: Sakspapir on Tue 27/06/2023 14:18:04This kind of works, but there is a "shaking" in the picture. Im assuming there is an issue with the order of which the drawing functions are called.

You're right, the reason is that RepExec is called too late, after the game was already drawn, so its changes apply to the next draw during the next game frame. This may seem strange, but it's how it is historically.

There's a special function for this kind of purpose, named "late_repeatedly_execute_always", it's run after game (and characters) are updated, but still before it's drawn. This is an ideal place to put such code.

For more details on script function orders you may check following article:
https://adventuregamestudio.github.io/ags-manual/GameEventsOrder.html

Sakspapir

Thanks a lot!

This solves my issues.

SMF spam blocked by CleanTalk