What's wrong with my moving code?

You must understand the Game Editor concepts, before post here.

What's wrong with my moving code?

Postby motorollin » Mon Aug 20, 2007 8:08 pm

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

Postby pixelpoop » Mon Aug 20, 2007 9:10 pm

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.
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby motorollin » Mon Aug 20, 2007 9:30 pm

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


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest