Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Slasher on Tue 02/05/2017 15:27:42

Title: Object follows GUI jutters
Post by: Slasher on Tue 02/05/2017 15:27:42
Hi,

Object follows GUI...

This is working but is there a better way so the object does not jutter as it moves..

The room has a vertical scroll.

Code (ags) Select

function repeatedly_execute_always()
{
oBar.Y=gGui2.Y+72 +GetViewportY();
}


cheers


Title: Re: Object follows GUI jutters
Post by: Cassiebsg on Tue 02/05/2017 15:30:00
Try placing it in the late_repeatedly_execute_always()  ;)
Title: Re: Object follows GUI jutters
Post by: Slasher on Tue 02/05/2017 15:46:52
Hi Cassiebsg ,

I'd forgotten about that new function. It does not stop the jitters though :~(

The reason why I have an object instead of a GUI is that I use it to position Char SayAt.. I did use a GUI and label during the intro.

cheers anyhow
Title: Re: Object follows GUI jutters
Post by: Khris on Tue 02/05/2017 18:37:05
You can use smooth movement:

float oBar_Y = 72.0;

function repeatedly_execute_always()
{
  int targetY = gGui2.Y + 72 + GetViewportY();
  oBar_Y += (IntToFloat(targetY) - oBar_Y) * 0.2; // <- laziness factor, try different values < 1
  oBar.Y = FloatToInt(oBar_Y, eRoundNearest);
}


The idea is to not move the object all the way but only by a certain fraction. The lower the factor, the lazier the movement.
Title: Re: Object follows GUI jutters
Post by: Slasher on Tue 02/05/2017 19:11:56
Hi Khris,

thanks for your help.

It's not quite perfect but a lot better with a few tweaks. The main problem to overcome is a jump-to by the object at the start.
It's part of an anti-gravity system.

cheers

EDIT: Jump at start sorted. We are almost 'good to go'  (nod)

cheers Khris

Title: Re: Object follows GUI jutters
Post by: Crimson Wizard on Thu 04/05/2017 12:43:06
I think if you could also lock and manually move Viewport (SetViewport function), using same smooth movement method, this may reduce jitter even futher.
Title: Re: Object follows GUI jutters
Post by: Slasher on Thu 04/05/2017 14:03:09
Hi Crimson,

QuoteI think if you could also lock and manually move Viewport (SetViewport function), using same smooth movement method, this may reduce jitter even futher.
I did. Time the player lowers 500 pxls there is a short time lag for the object to catch of with the gui.

If i raise the rate (float) the object goes a bit haywire when the room loads.

cheers

Title: Re: Object follows GUI jutters
Post by: Khris on Thu 04/05/2017 15:05:37
You can raise the value, but not above 1.0, otherwise it'll overshoot the target. If you want smooth but fast movement, use something like 0.8
Title: Re: Object follows GUI jutters
Post by: Slasher on Thu 04/05/2017 15:42:41
Hi Khris,

the movement is smooth. Going from bottom to top of screen ok but going top to bottom of screen the object seems to fall behind the gui about 10 pxls as it nears the bottom of the screen. Not  a big deal, just saying..

Res is 1024 x 768 room is 1024 x 1000

and i have to use 1.0 for the oBar and use in room load for it not to jump to position.
Code (ags) Select

oBar.Y=gGui2.Y+73 +GetViewportY(); 


cheers
Title: Re: Object follows GUI jutters
Post by: Khris on Thu 04/05/2017 16:19:47
Yes, you need to set an initial position, otherwise the object is going to start out being positioned elsewhere.
Using 1.0 however means you're short-circuiting the entire process; with 1.0 you should at least in theory see the exact behavior you started out with.

The main problem as I understand it is that you have a scrolling room with an object supposed to be positioned relative to a GUI, so whenever the room scrolls, you have to reposition the object to account for room vs. screen coordinates, right?

In this case it's probably a better idea to set the object's coordinate conventionally and use smooth scrolling for the viewport.
Title: Re: Object follows GUI jutters
Post by: Slasher on Thu 04/05/2017 16:57:10
This is almost perfect:

Room Load / Rep always
Code (ags) Select

oBar.Y=gGui2.Y+87 +GetViewportY();


Thanks for your help Khris (nod)

cheers
Title: Re: Object follows GUI jutters
Post by: Snarky on Thu 04/05/2017 17:17:45
Quote from: Slasher on Thu 04/05/2017 16:57:10
This is almost perfect:

Room Load / Rep always
Code (ags) Select

oBar.Y=gGui2.Y+87 +GetViewportY();


If you have this code in late_repeatedly_execute_always(), and it's not followed by any code that repositions gGui2, then there shouldn't be any "almost" about it: it should follow the GUI perfectly.