Making the view follow the actor

Non-platform specific questions.

Making the view follow the actor

Postby metaknight22 » Fri Jan 23, 2009 10:49 am

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????
Projects
Kirby Starship Game

I'm a newbie so I haven't done much.
User avatar
metaknight22
 
Posts: 25
Joined: Fri Jan 23, 2009 7:34 am
Score: 1 Give a positive score

Re: Making the view follow the actor

Postby asmodeus » Fri Jan 23, 2009 10:57 am

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.
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: Making the view follow the actor

Postby metaknight22 » Fri Jan 23, 2009 11:07 am

Thanks for that. :D
I'm almost finished my first basic game. :D
Though it's not that great.
Projects
Kirby Starship Game

I'm a newbie so I haven't done much.
User avatar
metaknight22
 
Posts: 25
Joined: Fri Jan 23, 2009 7:34 am
Score: 1 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron