Results 1 to 8 of 8
  1. #1
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Wink [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?
    Last edited by Lionlev; 10-15-2012 at 03:07 PM.
    WARNING I am Russian so it's possible that I wont understand you correctly...

  2. #2
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default 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
    WARNING I am Russian so it's possible that I wont understand you correctly...

  3. #3
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default 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
    WARNING I am Russian so it's possible that I wont understand you correctly...

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default 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.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: Hmmm how do I make a camera follow the player? (Platformer game)

    Yeah I did that to make the camera scrolling smoothly :D
    WARNING I am Russian so it's possible that I wont understand you correctly...

  6. #6
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: Hmmm how do I make a camera follow the player? (Platformer game)

    Ehh what?
    WARNING I am Russian so it's possible that I wont understand you correctly...

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: Hmmm how do I make a camera follow the player? (Platformer game)

    Nevermind, I removed that spammer;

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: Hmmm how do I make a camera follow the player? (Platformer game)

    Quote Originally Posted by JosAH View Post
    Nevermind, I removed that spammer;

    kind regards,

    Jos
    Oh ok thanks
    WARNING I am Russian so it's possible that I wont understand you correctly...

Similar Threads

  1. 2 player java game
    By nuubik in forum New To Java
    Replies: 1
    Last Post: 11-07-2011, 02:05 PM
  2. Platform Game |Player Not Showing Up|
    By petur170 in forum New To Java
    Replies: 16
    Last Post: 06-28-2011, 05:16 PM
  3. How to make a Java mp3/mp4 player?
    By Java123 in forum New To Java
    Replies: 2
    Last Post: 01-10-2011, 10:08 PM
  4. How to add online two player to a Java game?
    By michealsmith in forum Java Gaming
    Replies: 1
    Last Post: 11-30-2010, 07:43 PM
  5. how to log into a game with my player.java class
    By basketball8533 in forum New To Java
    Replies: 11
    Last Post: 10-13-2010, 12:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •