Change room scrolling deadzone?

Started by The creature, Thu 20/09/2018 20:51:29

Previous topic - Next topic

The creature

Hi

I've googled for an answer but haven't had much luck. I'm working on a little project and the bottom of the screen is taken up by a GUI bar that is always visible (that is about 50px tall). Is there a way to manually set the dead-zone of the room scroll in code? So, basically, the player character doesn't have to walk behind the GUI to scroll the screen down in Y?

I've searched the manual too for a simple bit of code (with SetViewPort, etc). Any help would be great because it would be cool to have larger rooms in the Y.

Kind Regards
C.

VampireWombat

#1
If I understand what you want correctly, can't you just add a section to your background image that's 50 pixels high?
I tested it with the Tumbleweed Template and it works for me. Unless you're wanting something different than I understood.

Crimson Wizard

#2
Quote from: VampireWombat on Thu 20/09/2018 21:43:12
If I understand what you want correctly, can't you just add 50 black pixels at the bottom of your background image?

I think OP's problem is that he or she has a scrolling room, and since by default AGS centers view on character having whole screen in mind, character may be seen too close to GUI in the lower half, while author wants to see character centered inside the remaining upper half of the screen.


If it's what I think, by coincidence I am working to add this feature into engine right now, but it will take a while.
Meanwhile the only way is to write custom camera code. Use SetViewport() in repeatedly_execute_always() and point to your player character. Then you will be able to apply any kind of adjustments and constraints.
Have something like this in GlobalScript.asc, or any custom module:
Code: ags

#define CUSTOM_VIEWPORT_WIDTH 320 // game's width
#define CUSTOM_VIEWPORT_HEIGHT 150 // game's height minus GUI height

// Notice I am using late_repeatedly_execute_always, it is run after game updates itself (contrary to just repeatedly_execute_always which is run before game update), and this way you will be getting most up-to-date player's location.
function late_repeatedly_execute_always()
{
   // First get the point camera should be targetting
   int x = player.x;
   int y = player.y;
   // NOTE: add some offset to x and y to take character's size in account, because x,y point to character's feet
   
   // Now center the player in the custom viewport
   x -= CUSTOM_VIEWPORT_WIDTH / 2;
   y -= CUSTOM_VIEWPORT_HEIGHT / 2;
   // Make sure coordinates don't go below 0 (don't remember how AGS reacts to that)
   if (x < 0) x = 0;
   if (y < 0) y = 0;
   
   SetViewport(x, y);
}



EDIT: but indeed you still will have to have 50 px dummy border in the room if you want character to walk all the way down the active background.

The creature

Crimson hit the nail on the head - I;ve just recently downloaded the latest ags anf it's great to see the new things in it. I'll use the function below for now, I just wanted to have a little bit of zone where the camera didn't move constantly with the character - like it does now.

I guess the ideal would be to have something like the Display Edge (the yellow lines) in the room editor but when the player enters such a zone the viewport then follows the character (until it obviously hits the room art boundary), This is great though.

Thanks for the support.
C

SMF spam blocked by CleanTalk