Page 1 of 1

Smoother Scrolling

PostPosted: Sun Aug 27, 2006 6:25 am
by Cleve_Blakemore
The quickest way to get the viewport to follow your character on your tilemap/level artwork is to parent the view. The problem is that it results in rough scrolling because the view is anchored to your player actor and if you are moving it 2-6 pixels at a time the view moves with it, with no intermediate frames to smooth the motion out.

For both the isometric game and the platformer I've been working on, I tried another method instead, which is to compute where the viewport center should be and use a MoveTo command to slide it there at a uniform rate. This results in much smoother scrolling around following the character.

It looks tons better for platform games but for overhead maps/isometrics it is a must. Otherwise the rough scrolling at resolutions above 640x480 becomes too noticeable.

PostPosted: Sun Aug 27, 2006 1:49 pm
by makslane
You can smooth the view move by removing the parent and using a little code. In the 'Draw Actor' event of the view:


Code: Select all
double weight = 10;

x = ((weight  - 1)*x + player.x)/weight ;
y = ((weight  - 1)*y + player.y)/weight ;


Change the weight value to get the right movement for you.

PostPosted: Wed Sep 06, 2006 10:12 pm
by SergeLo00001
ok i do this and the scrolling looks good, but once i start the game everything just rushes to the top and i can only see the bottom half of the player and verything below that point. why?

PostPosted: Thu Sep 07, 2006 12:29 pm
by makslane
I'm sorry, you must take account the view size too:

Code: Select all
x = ((weight  - 1)*x + player.x)/weight - width/2;
y = ((weight  - 1)*y + player.y)/weight - height/2;

PostPosted: Thu Sep 07, 2006 2:47 pm
by Jokke
so THATS why it didnt work for me too XD

PostPosted: Mon Sep 25, 2006 8:03 pm
by pavel329
just make the player the views parent.works really easy for me.goes very smooth.but it goes in all directiong to if you don't want your charcter to be seen when he's falling to his doom just use the event disable.

PostPosted: Sat Oct 21, 2006 2:40 am
by SergeLo00001
i put this in draw actor of view:
double weight = 10;
x = ((weight - 1)*x + SergeLo.x)/weight - 1200/2;
y = ((weight - 1)*y + SergeLo.y)/weight - 480/2;

SergeLo is the player
The view is 1200 by 480

When i start the game everything goes black.

PostPosted: Sat Oct 21, 2006 2:45 am
by SergeLo00001
has this wroked for anyone yet??
The whole smoothing thing worked, i coud've seen that when i didn't include the view/2 thing at first.... Just that when i do include it, it looks like the view rapidly shoots away into some direction when i start the game.
Plz Help :cry:
I really like this view smoothing thing

PostPosted: Sat Oct 21, 2006 2:50 am
by SergeLo00001
O, and Jokke....
How does that Bum in ur signature know all that... :shock:
He's right!

PostPosted: Sat Oct 21, 2006 2:53 am
by SergeLo00001
SergeLo00001 wrote:He's right!

sweet, figured out how ppl do this... 8)

PostPosted: Sat Oct 21, 2006 2:22 pm
by makslane
Sorry again. I think I need to sleep a little more!
The right solution is:

Code: Select all
double weight = 10;

x = ((weight  - 1)*x + (player.x - width/2))/weight;
y = ((weight  - 1)*y + (player.y - height/2))/weight;

PostPosted: Fri Oct 27, 2006 5:33 am
by SergeLo00001
the view still doesnt stay in poition :(
once you move with the actor that is child to view, the view moves to a direction the view movest faster than my character.

Am i doing something wrong?

PostPosted: Fri Oct 27, 2006 12:34 pm
by makslane
If you want to use this code to control the view, use with an actor that is not child of the view.

PostPosted: Fri Nov 24, 2006 11:36 am
by Cleve_Blakemore
makslane wrote:If you want to use this code to control the view, use with an actor that is not child of the view.


I will put up a small demo sometime in the next week or so to show this in action. Improves the render quality and appearance dramatically for most games.