[Solved] Litlle camera scrolling issue

Started by actaria, Wed 30/11/2022 22:24:28

Previous topic - Next topic

actaria

Hello,

It's me again. :-D
Today i am learning Camera function.

I have a 1980x5500 room and i wanted to make a Camera scrolling from the top to the bottom of the room to show the player what he will have to climb.

I managed to do the scrolling i wanted with this code and it works really well

Code: ags

// Create and setup a temporary camera
Camera* myCam = Camera.Create();

myCam.SetAt(0, 0);


// Save the old camera in a temp variable
Camera* oldCam = Screen.Viewport.Camera;
// Assign the new camera to the primary viewport
Screen.Viewport.Camera = myCam;

// Scroll the new camera across the room
while (myCam.Y < (Room.Height - myCam.Height))
{
    myCam.SetAt(myCam.X + 1, myCam.Y + 10);
    Wait(1);
}

// Delete the camera and reset the old camera back
myCam.Delete();
Screen.Viewport.Camera = oldCam;


The only little problem i have is that when you enter the room the camera shows the player for like 1 second before going to the top of the room to begin the scrolling down.

I thought that myCam.SetAt(0, 0); was what the camera shows at start but even if i changes the values it still shows the player at start.

Any help to explain would be appreciated.

Thank you.

Khris

#1
I assume this code is inside the after fadein function? If so, add the before fadein function and use the code like this:

This goes inside room_Load (before fadein event function)
Code: ags
  Screen.Viewport.Camera.SetAt(0, 0);

Put this inside room_AfterFadein
Code: ags
  Camera* cam = Screen.Viewport.Camera;
  while (cam.Y < Room.Height - cam.Height)
  {
    cam.SetAt(cam.X, cam.Y + 10);
    Wait(1);
  }
  // reset camera to follow player
  cam.AutoTracking = true;

Edit: fixed code to not use a secondary camera

actaria

Hello Kris,

My savior as usual, well what can i say many big thanks you are really amazing each time.

It works really well thanks you so much i can continue the spiders cave now  :-D



Crimson Wizard

#3
I do not think that creating a second camera is necessary here. This is a common camera scroll case, in this situation you could simply move existing camera, and result will be exactly the same.

actaria

#4
Hello Crimson Wizard,

This is the first time i use Camera functions so i copy paste the manual  :-D

It's good to know that i can use the main camera to get the exact same result.

I will try this soon since i have another room where i will need the camera.

So i have to test this and also:

function on_mouse_click(MouseButton button) {
  if (player.View == DEATH) ClaimEvent();
}

that you told me for my player deaths, she will die soon again no worries

Thank you.

Crimson Wizard

Quote from: actaria on Wed 30/11/2022 23:27:39This is the first time i use Camera functions so i copy paste the manual

I guess this means that the example in the manual is misleading, I will try to change it.

actaria

#6
Quote from: Crimson Wizard on Thu 01/12/2022 00:01:44
Quote from: actaria on Wed 30/11/2022 23:27:39This is the first time i use Camera functions so i copy paste the manual

I guess this means that the example in the manual is misleading, I will try to change it.

I don't know maybe this is just me  :-D
I managed to do the scrolling thing after a few times reading it so the manual is good.
I just though that i had to create a new camera to do the scrolling.

Crimson Wizard

#7
Quote from: actaria on Thu 01/12/2022 00:29:32I don't know maybe this is just me  :-D
I managed to do the scrolling thing after a few times reading it so the manual is good.
I just though that i had to create a new camera to do the scrolling.

No, it's the manual that makes a wrong impression.

I just checked it, and the example makes no sense. At the same time there's no example of a proper simple scrolling (for example, for SetAt article).

It's quite possible that more people have already used the wrong method because of this. Maybe it even makes sense to release a new patch for 3.5.1 to prevent this problem in the future.

Khris

I've edited my post above accordingly. :)

actaria

Quote from: Crimson Wizard on Thu 01/12/2022 02:25:09
Quote from: actaria on Thu 01/12/2022 00:29:32I don't know maybe this is just me  :-D
I managed to do the scrolling thing after a few times reading it so the manual is good.
I just though that i had to create a new camera to do the scrolling.

I just checked it, and the example makes no sense. At the same time there's no example of a proper simple scrolling (for example, for SetAt article).


True this is exactly what i was thinking wihle i was reading the manual i wanted a proper example of a simple scrolling like the one i used

This would be nice if you can write a simple scrolling example from top to bottom or from left to right and how to change the scrolling speed.

Thanks again for all the things you are doing to make AGS even better.

actaria

Quote from: Khris on Thu 01/12/2022 11:12:18I've edited my post above accordingly. :)

Thank you Khris i will change my code then to do things the right way  :-D

Crimson Wizard

Updated the examples here:
https://github.com/adventuregamestudio/ags-manual/wiki/Camera
https://github.com/adventuregamestudio/ags-manual/wiki/Viewport

Besides the strange scrolling example, I found couple of minor mistakes. Rewrote the zoom examples to keep aspect ratio.

Maybe will release a patched 3.5.1 version in a few days.

actaria

I just had a look and this is really nice especially the zoom exemple with respected ratio.
i will use it sooon for sure  :-D
Great job thanks.

SMF spam blocked by CleanTalk