Scripting "view" movement

Non-platform specific questions.

Scripting "view" movement

Postby motorollin » Wed Aug 15, 2007 11:36 am

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:

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?
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score

Postby motorollin » Wed Aug 15, 2007 12:13 pm

Well I figured it out :D

Enemy collision event with player:
Code: Select all
DestroyActor("player");
CreateTimer("view", "viewmove", 10);


¨View¨ timer event for ¨viewmove¨ timer:
Code: Select all
if ( view.x < viewstartx ) view.x += 5;
if ( view.x > viewstartx ) view.x -= 5;
if ( view.y < viewstarty ) view.y += 5;
if ( view.y > viewstarty ) view.y -= 5;

if ( view.x == viewstartx & view.y == viewstarty )
{
    DestroyTimer("viewmove");
    CreateActor("player", "playerup", "(none)", "(none)", playerstartx, playerstarty, true);
}
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score

Postby motorollin » Wed Aug 15, 2007 12:26 pm

Hmmm this works in GE but not on the GP2X. The view moves in the wrong direction on the GP2X. Any ideas why this might be?
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score

Postby motorollin » Thu Aug 16, 2007 10:06 am

It turns out the code does work, but the imprecise positioning of my game elements were causing problems getting the view aligned back to where it needs to be. Once I precisely aligned everything (Create Actor event -> Script -> x=blah; y=blah; ), then used those values to check for the position of the view, it worked.
motorollin
 
Posts: 54
Joined: Sun Aug 12, 2007 8:05 am
Score: 1 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron