Scripting "view" movement

In my game the view scrolls around as the player moves, but when the player dies it moves back to the center of the playfield. Currently the view just jumps back to its correct position, but I want it to scroll smoothly back in to position. I tried doing this:
The playfield did move back to the correct position, but it was so fast that it jumped instead of scrolling. Next I tried this:
(repeated for each direction)
This does slow down the movement, but not in the way I want. The game freezes for the duration of the while loop then the view jumps to where it needs to be.
I then thought of trying directional_velocity:
(repeated for each direction)
This resulted in the game hanging. Presumably this is because the view did not respond to the directional_velocity command, so never reached its target location, thus the while loop never completed.
Can anyone offer any advice on how I can achieve this?
- Code: Select all
while ( view.x < viewstartposx )
{
view.x+=1;
}
while ( view.x > viewstartposx )
{
view.x-=1;
}
while ( view.y < viewstartposy )
{
view.y+=1;
}
while ( view.y > viewstartposy )
{
view.y-=1;
}
The playfield did move back to the correct position, but it was so fast that it jumped instead of scrolling. Next I tried this:
- Code: Select all
while ( view.x < viewstartposx )
{
if ( viewmove == 1000 )
{
view.x+=1;
viewmove=0;
}
else
{
viewmove+=1;
}
}
(repeated for each direction)
This does slow down the movement, but not in the way I want. The game freezes for the duration of the while loop then the view jumps to where it needs to be.
I then thought of trying directional_velocity:
- Code: Select all
while ( view.x < viewstartposx )
{
view.angle=0;
view.directional_velocity=5;
}
view.directional_velocity=0;
(repeated for each direction)
This resulted in the game hanging. Presumably this is because the view did not respond to the directional_velocity command, so never reached its target location, thus the while loop never completed.
Can anyone offer any advice on how I can achieve this?