Best way to have the camera follow my hero


(Nate ) #15

Also this is a very noob question… but I am currently adding my player in the world class with this line… what would I have to do to be able to access the X and Y value of the player from the world class?

add(new thePlayer);

(Kevin Graham) #16

The only difference is mine is called player, and yours is thePlayer, so replace the player accordingly.


(Kevin Graham) #17

thePlayer.x and thePlayer.y


(Nate ) #18

Okay I have addressed all of the player issues, but I am not sure what to put for mapWidth and mapHeight. I tried manually putting in the stage information but that then made my character move from spawn.


(Nate ) #19

Okay everything is compiling but I am not sure what to do for mapWidth and mapHeight still! D: My character is moving and such, the camera doesn’t follow him though.


(Kevin Graham) #20

You could do it manually if all your levels are going to be the same size, but what i’ve done is set the variables from the ogmo level file when I load it.


World States [several questions]?
(Nate ) #21

Okay! I just figured it out! I had manually set the width to the size of the stage so it wasn’t doing anything! But it is now working! Thanks a lot Shadow!

My next question is going to be inserting a nice scrolling backdrop which will mainly just be clouds and such!


(Kevin Graham) #22

That sounds like a problem with accessing the x and y of your player. Can you post your whole world file?


(Nate ) #23

I got everything workin! In order to access the X and Y coordinates of my player class, inside of my world class I used these four lines of code, in their respectful places:

		import entities.thePlayer;

		private var hero:thePlayer;

		hero = new thePlayer;
        add(hero);

Then in order to access the X and Y coordinates in the camera code I used hero.x and hero.y respectfully!


(Kevin Graham) #24

Glad to hear it!if you don’t want to have to set it manually because you have different level sizes let me know. Glad I could be of help! :smile:


(Nate ) #25

Okay! Thanks again for the assistance Shadow!

What would you suggest for me to insert some clouds to float by in the backdrop area?


(Kevin Graham) #26

If you want them to move independently of the walls and such, I have code for a scrolling BG in another of my games, but I won’t be able to post it for a few days :confused: I work tomorrow and then have plans as its my b-day, but ill post it as soon as I can. It consists two copies of the background that scroll, and leapfrog over each other as they go off screen.


(Nate ) #27

Okay sounds like a plan! Keep me posted man! And happy early birthday!! :smiley:


(Kevin Graham) #28

Also, another thing that could be cool, is you could have a few cloud objects that get moved to a random y location on the right side of the screen when they move off the left. This would look lest repetitive. Then you could have a solid blue BG behind them.


(Kevin Graham) #29

Haha thanks, and will do!


(Nate ) #30

Yea I was thinking to have some random clouds generated at different Y values and then have them move across the screen at a fixed slow rate. :smiley:


(Kevin Graham) #31

Sweet. If you need help with that let me know and I’ll help you out as soon as I can in a few days.


(TheHuckleberryWill) #32

Just coded that in my current game, its nice if you have a base speed, then multiply that by each clouds image scale - looks pretty cool that way.


(Nate ) #33

Shadow I will shout if I need anything! Thanks again for hooking up the scrolling code!

HuckleberryWill! I will look into doing something like that for my clouds, thanks!


(christopf) #34

Hi, i just tried to implement this but when i created a override update function in my world.as my hero entity froze. so i dropped it off and put the 2 fp.camera lines in the update function of the hero.as but after this the hero just dissappeared off the screen. what did i wrong?