Object follows GUI jutters

Started by Slasher, Tue 02/05/2017 15:27:42

Previous topic - Next topic

Slasher

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

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


cheers



Cassiebsg

Try placing it in the late_repeatedly_execute_always()  ;)
There are those who believe that life here began out there...

Slasher

#2
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

Khris

You can use smooth movement:

Code: ags
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.

Slasher

#4
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


Crimson Wizard

I think if you could also lock and manually move Viewport (SetViewport function), using same smooth movement method, this may reduce jitter even futher.

Slasher

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


Khris

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

Slasher

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

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


cheers

Khris

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.

Slasher

This is almost perfect:

Room Load / Rep always
Code: ags

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


Thanks for your help Khris (nod)

cheers

Snarky

Quote from: Slasher on Thu 04/05/2017 16:57:10
This is almost perfect:

Room Load / Rep always
Code: ags

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.

SMF spam blocked by CleanTalk