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 10 of 10

Thread: Grid movement randomly not working

  1. #1
    Member
    Join Date
    Jun 2011
    Posts
    30
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question Grid movement randomly not working

    ..............
    Last edited by pajfilms; May 4th, 2012 at 01:18 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,408
    Thanks
    49
    Thanked 2,213 Times in 2,186 Posts

    Default Re: Grid movement randomly not working

    sometimes it moves two tiles in the grid even though I'm not holding down an arrow key.
    You need to debug your code to see what is happening.
    Add some printlns to show the values of the variables as they are changed and as they are used to move the image.

  3. #3
    Member
    Join Date
    Jun 2011
    Posts
    30
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Grid movement randomly not working

    ..............
    Last edited by pajfilms; May 4th, 2012 at 01:18 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,408
    Thanks
    49
    Thanked 2,213 Times in 2,186 Posts

    Default Re: Grid movement randomly not working

    it sometimes doesn't hit zero,
    Look at your logic to see if the image's next movement will go past the bounds of the grid and stop its moving at that point. For example if it is at 31 and moves by 2 it will skip over 32.
    So before the move test if the change of position will move the image past its stopping point.

  5. #5
    Member
    Join Date
    Jun 2011
    Posts
    30
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Grid movement randomly not working

    ..............
    Last edited by pajfilms; May 4th, 2012 at 01:18 PM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,408
    Thanks
    49
    Thanked 2,213 Times in 2,186 Posts

    Default Re: Grid movement randomly not working

    Look at the logic where you change the x,y values for a move.
    Check if the new position will cross a boundary and if the movement should stop.
    If it should stop, set the new location to be on the boundary and signal a stop.

  7. The Following User Says Thank You to Norm For This Useful Post:

    pajfilms (August 27th, 2011)

  8. #7
    Member
    Join Date
    Jun 2011
    Posts
    30
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Grid movement randomly not working

    ..............
    Last edited by pajfilms; May 4th, 2012 at 01:18 PM.

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,408
    Thanks
    49
    Thanked 2,213 Times in 2,186 Posts

    Default Re: Grid movement randomly not working

    It snaps into place
    How else would you change the movement into the next postion if it was past where you want it to stop?

    I did not say to continue using the % 32 logic. Perhaps that is not the way to recognize where the boundaries are.

  10. The Following User Says Thank You to Norm For This Useful Post:

    pajfilms (August 27th, 2011)

  11. #9
    Member
    Join Date
    Jun 2011
    Posts
    30
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Grid movement randomly not working

    ..............
    Last edited by pajfilms; May 4th, 2012 at 01:18 PM.

  12. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,408
    Thanks
    49
    Thanked 2,213 Times in 2,186 Posts

    Default Re: Grid movement randomly not working

    There are usually more than one way to solve a problem.
    Simpler is often better.

Similar Threads

  1. Threads are killed randomly in While true loop
    By kurt-hardy in forum Threads
    Replies: 7
    Last Post: August 11th, 2011, 07:55 AM
  2. thought i had it, then i sneezed and lost it (randomly generated numbers)
    By fakeClassy in forum Java Theory & Questions
    Replies: 13
    Last Post: July 17th, 2011, 04:16 PM
  3. 3D camera movement
    By macko in forum Java Theory & Questions
    Replies: 2
    Last Post: May 17th, 2011, 07:53 AM
  4. Grid bag layout inside grid bag layout
    By kiddkoder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 29th, 2011, 08:07 AM
  5. movement
    By mlan in forum Java Theory & Questions
    Replies: 4
    Last Post: February 15th, 2010, 09:57 PM

Tags for this Thread