Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: is there any good formula's for 2d java game - to make ur player move right or left?

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default is there any good formula's for 2d java game - to make ur player move right or left?

    when user hit right key, walk_right get to set to true and when user left go of right key, walk_right get set to false.
    i have really basic code to make my player move right or left.

    i was wondering if there are any good physics formulas, to move right or left. and i dont mean jump. just right or left.


    while(true){
       if(walk_right == true){
              x += dx;
        }
        else if(walk_right == false){
        }
     
     
          if(walk_left == true) {
    		x -= dx;     
    	 }
          else{
            }
    }


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: is there any good formula's for 2d java game - to make ur player move right or le

    I see many posts on the forum related to movement in this 2D game. I think part of the problem is in code not yet shown.

    Post the code that shows the event handlers for the key listener. Also post any other code related to movement of the player.

  3. The Following User Says Thank You to jps For This Useful Post:

    hwoarang69 (October 24th, 2012)

Similar Threads

  1. How can i make my Player attack another Player?
    By Graser in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 31st, 2012, 05:01 PM
  2. Player wont move
    By jokr in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 25th, 2012, 09:46 AM
  3. java game bullets hit player 1 but not player 2
    By ajakking789 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 22nd, 2011, 08:19 AM
  4. java game, both players move for player 2 but not player 1
    By ajakking789 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 21st, 2011, 12:52 PM
  5. Getting my paddle to move left and right in a straight line-STUCK
    By warnexus in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 20th, 2011, 08:06 PM