[FIXED] Hmmm how do I make a camera follow the player? (Platformer game)
Hello, I know I quite made already lots of threads, but that's the only way I can learn, or contact with when I've got a problem with java..
I mean I didn't go to any school or anything...
Anyways, I've got two rectangles, one of them is a player and other is just a platform that just stands there, and being forever alone...
But the player can move and jump.
So I want the camera follow the player
How would I do that?
Re: Hmmm how do I make a camera follow the player? (Platformer game)
Ok I figured that out after 5 hours of thinking xD
If someone else need to know, here is how I did it:
Basically there is no such thing as "Camera" in java, which means you should make it your self by MOVING everything..
So, I've created 2 variables called camX and camY basically they will position the camera where you want, for now I set them to 0.
Next when I draw rectangles or images I add "-camX" to the x of the object, and same for the Y ("-camY") and where you have the changes of the rectangle's position like "rect.X +=5" (just example) you should add "camx += 5" right after that, and there you have it, a simple camera system.
I didn't figure it out how to make the camera follow rect smoothly yet tho.. But I think I am close
Re: Hmmm how do I make a camera follow the player? (Platformer game)
Ok I've managed to make the camera smooth, if anyone interested just ask
Re: Hmmm how do I make a camera follow the player? (Platformer game)
What you want to do is separate your world's "model" coordinate system from the screen's coordinate system. Then you can more easily do things like scrolling, moving the camera, zooming in and out, and supporting different screen sizes and resolutions.
Re: Hmmm how do I make a camera follow the player? (Platformer game)
Yeah I did that to make the camera scrolling smoothly :D
Re: Hmmm how do I make a camera follow the player? (Platformer game)
Re: Hmmm how do I make a camera follow the player? (Platformer game)
Nevermind, I removed that spammer;
kind regards,
Jos
Re: Hmmm how do I make a camera follow the player? (Platformer game)
Quote:
Originally Posted by
JosAH
Nevermind, I removed that spammer;
kind regards,
Jos
Oh ok thanks