Page 1 of 1
Follow view without parenting or moving bug
Posted:
Wed May 29, 2013 3:31 am
by Hblade
If you want to "stick" something to the view without it glitching out when moving (or without parenting) the solution is simpler than you think
All you have to do is put this in draw actor of the follower:
- Code: Select all
x=view.x/1;
y=view.y/1;
You might have to do this if you have a background thats large:
- Code: Select all
x=view.x/1+(width/2);
y=view.y/1+(height/2);
Why /1? Because without that, you can see the background move a bit when the view moves, but by dividing it by 1 for some reason its instant
Re: Follow view without parenting or moving bug
Posted:
Wed May 29, 2013 4:00 am
by skydereign
Hblade wrote:Why /1? Because without that, you can see the background move a bit when the view moves, but by dividing it by 1 for some reason its instant
Dividing by 1 makes it cast it to an int (losing the floating point). This helps because x and y values are doubles, which gE rounds up or down when actually drawing.
Hblade wrote:- Code: Select all
x=view.x/1;
y=view.y/1;
You can do the same thing with xscreen, and not need to cast it to an int.
- Code: Select all
xscreen = 0;
yscreen = 0;
Re: Follow view without parenting or moving bug
Posted:
Wed May 29, 2013 4:27 am
by Hblade
Thanks lol, I thought xscreen=0 and yscreen=0 would cause the same effect as the moving glitch (If the view moves super fast, the background moves differently than the view, which is why somehow I discovered /1 prevents that and sticks it ^_^
) But yeah thanks, didn't know xscreen=0 is different than x=view.x
Re: Follow view without parenting or moving bug
Posted:
Wed May 29, 2013 5:14 am
by skydereign
Ah, actually there does seem to be a slight difference. Setting xscreen essentially sets it to the current view position, but setting x to view.x sets it after the view has moved. This is rather odd, and probably shouldn't happen, but that's how it currently stands (which is why view.x and xcreen do different things for you). Though the /1 does not do anything if the view is moving at integer amounts, again due to no need to cast.
Re: Follow view without parenting or moving bug
Posted:
Wed May 29, 2013 5:18 am
by Hblade
Ahh right, but wouldn't you be able to do a similar effect using round? x=round(view.x); that would be the same as /1 correct? or xscreen
Re: Follow view without parenting or moving bug
Posted:
Wed May 29, 2013 5:24 am
by skydereign
No, rounding rounds up and down depending on the floating point (round(5.9) = 6). Dividing by 1 casts it as an int, meaning 5.9/1 = 5. You could use floor instead though.
Re: Follow view without parenting or moving bug
Posted:
Wed May 29, 2013 5:48 am
by Hblade
Oh! Never knew what floor did
So, floor(2.3); would mean 2, as well as floor(2.9). I see, so floor basically completely removes the decimal(s).
Re: Follow view without parenting or moving bug
Posted:
Mon Jun 03, 2013 8:39 pm
by bat78
it works also with ceil(), but it will be with 1 bit slower.
Re: Follow view without parenting or moving bug
Posted:
Tue Jun 04, 2013 3:19 am
by Hblade
So /1 is the best way :3?
Re: Follow view without parenting or moving bug
Posted:
Tue Jun 04, 2013 4:39 am
by skydereign
No, if you want to cast it, actually do the cast (or use floor). Dividing by 1 is just weird.
- Code: Select all
int var = (int)4.9;
// var is set equal to 4
Re: Follow view without parenting or moving bug
Posted:
Tue Jun 04, 2013 5:14 am
by Hblade
Thanks
Weird that now when I try, it actually keeps up O.o no matter how I do it. Lol this was confusing