Switch camera/view port in a big background [SOLVED]

Started by Giacomo, Tue 17/08/2021 11:02:27

Previous topic - Next topic

Giacomo

Hi eveyone!

I'm sorry I can't solve the following problem on my own...

So, I have 320x240 screen resolution.

The room's background is a triptych which is 960x360 (There's an upper part also).

I'd like to set the camera to the left portion of the background so that
when the player reaches the right border, the camera scrolls rapidly to the second part
of the background, and same thing for the third part.

In the third part, the player takes a look up and there i'd like the camera to move
up to show the sky.

How is that possible?

Here's a graphic example.

https://imgur.com/uHASYHk

Thank you all in advance!
https://ko-fi.com/giacomo97557 To support Falco's adventures

Crimson Wizard

#1
Hello.

This is pretty easy to do, game camera is accessed like Game.Camera and has X and Y properties that may be changed anytime similar to any other object in game. Changing them in a loop produces the behavior you would want. Setting them to anything actually stops camera from following a player. Another way to control this is AutoTracking property (could be true or false).

EDIT: This solution refers to AGS 3.5.0 and later, if you are working in the previous versions then you will have to use differently named functions, but it's still all possible.

So, first thing you do in a new room you disable the player tracking by either setting camera's X & Y to certain position, or setting AutoTracking to false. The first is probably better because you need it to be in certain location:
Code: ags

Game.Camera.X = 0;
Game.Camera.Y = CAM_HEIGHT; // some offset, because you also have a "sky" part of the room above

or alternatively:
Code: ags

Game.Camera.SetAt(0, CAM_HEIGHT);


You may detect camera need to move either by having a region triggering this when player stands on it, or by testing for player position related to camera in the room's "repeatedly execute" function. I guess you know the first method, the second looks about like this:
Code: ags

if (player.x < Game.Camera.X + SOME_OFFSET) {
     // move camera to left
} else if (player.x >= Game.Camera.X + Game.Camera.Width - SOME_OFFSET) {
     // move camera to right
}


The camera movement itself is, like said above, just a change of X/Y in a loop. It may be blocking or non-blocking, but in your case I think it should be a blocking animation. For example, following would move camera right:
Code: ags

int new_x = Game.Camera.X + Game.Camera.Width;
while (Game.Camera.X < new_x) {
    Game.Camera.X += DISTANCE_PER_GAME_TICK;
    if (Game.Camera.X > new_x) {
        Game.Camera.X = new_x; // snap it to make sure it does not go any further
    }
    Wait(1); // makes engine update the screen
    // you may also play with the speed/delay numbers to find a good combination
}



Couple of last things.

If you do or plan to have numerous similar animations in your game, I recommend checking out the Tween module that has functions for moving and changing objects (including cameras) in time in various ways: https://www.adventuregamestudio.co.uk/forums/index.php?topic=57315.0

I made a Camera Tech Demo game recently, it has open source, and meant to show people how to manipulate cameras in the newest versions of AGS: https://www.adventuregamestudio.co.uk/forums/index.php?topic=59272.0

Giacomo

Hi Crimson,
thank you very much for your exhaustive reply.

I am having a hard time to make the camera scroll smoothly,
and will use your demo script to do it. The bridge quest is just
fine for my aim!.

Tween module is awesome too and thanks for introducing it to me!
I am pretty sure I am gonna use it on the days on.

Best regards,
Giacomo
https://ko-fi.com/giacomo97557 To support Falco's adventures

SMF spam blocked by CleanTalk