Best way to have the camera follow my hero


(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?


(christopf) #35

Further i found my hero after subtracting a decent value off the FP.halfWeight and FP.halfHeight. Could it be that these both doesnt recognize the FP.sceen.scale (of 2) in the engine class?


(Ultima2876) #36

Did you make sure that when you had it in your engine’s update override, you were calling super.update() from within the engine update override as well? If you do not call super.update, your entities (player!) will not get updated and it will have that ‘freezing’ effect!


(christopf) #37

Jep you got it, thanks!