Page 1 of 1

Making the view follow the actor

PostPosted: Fri Jan 23, 2009 10:49 am
by metaknight22
I'm trying to get my character to always be in the centre of the screen but I didn't understand the tutorials...
Can anyone explain this clearly????

Re: Making the view follow the actor

PostPosted: Fri Jan 23, 2009 10:57 am
by asmodeus
The view is like an actor. You can use view.x and view.y to change the position of the view. If your actor's name is myactor, you could use this code in the draw event of the view:
Code: Select all
// BAD CODE!!!
x = myactor.x;
y = myactor.y;

The problem is now, that the actor isn't in the center of the view, it is in the upper left corner of the view. To bring it in the center, you should know the width and height of the view (I think you can use the variables width and height).
You can finally use this code:
Code: Select all
// use this in draw event of view
x = myactor.x-width/2;
y = myactor.y-height/2;

I hope that helps you.

Re: Making the view follow the actor

PostPosted: Fri Jan 23, 2009 11:07 am
by metaknight22
Thanks for that. :D
I'm almost finished my first basic game. :D
Though it's not that great.