Page 1 of 1

What's wrong with my moving code?

PostPosted: Mon Aug 20, 2007 8:08 pm
by motorollin
My player actor has 8 key down events which set its angle and velocity in each of 8 directions. Key up events then stop it when the key is released. This works well, but each key down event has to move quite a lot of things. For example, the ¨up¨ key pressed event:

Code: Select all
player.angle=90;
player.directional_velocity=playerspeed;
view.angle=90;
view.directional_velocity=playerspeed;
Life_count.angle=90;
Life_count.directional_velocity=playerspeed;


This does work, but clearly as I add move objects which need to scroll (interface elements etc) I am going to have to add lines of code to all 8 directions. This is messy and time consuming. So I wanted to condense this to the following:

Code: Select all
move(90);


or whichever angle it is for the direction pressed, then this in the main code:

Code: Select all
void move(int moveangle)
{
    player.angle=moveangle;
    player.directional_velocity=playerspeed;
    view.angle=moveangle;
    view.directional_velocity=playerspeed;
    Life_count.angle=moveangle;
    Life_count.directional_velocity=playerspeed;
}


That way I only have to add two lines to the move() function each time I add an object which has to scroll with the player. However, when I did this the only object which moved was player. View and Life_count stayed where they were - their velocity did not change. I can't see what's wrong with my code so would really appreciate some help!

PostPosted: Mon Aug 20, 2007 9:10 pm
by pixelpoop
You should use parenting, parented objects follow their parents. If the score and lives counter will always be in the upper right corner of the view, then select them and change their parent to the view actor. If the player will always be in the middle of the screen then the views parent should be the player actor.

PostPosted: Mon Aug 20, 2007 9:30 pm
by motorollin
I thought parenting just kept co-ordinates relative if they needed to be. I didn't realise child objects followed their parents. Thanks very much! :D