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.


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

Results 1 to 3 of 3

Thread: Tile Collision

  1. #1
    Junior Member
    Join Date
    May 2012
    Thanked 0 Times in 0 Posts

    Question Tile Collision

    I have multiple tiles in an array list. I want to set collision between them and the player. Currently, I am trying to do the collision check by a static boolean in the player class, but with this:

    		for(int i = 0; i < tiles.size(); i++) {
    			if(tiles.get(i).collision) {
    				Player.collision = true;
    				Player.collision = false;

    I'm guessing you can tell that if any of the tiles do not have the collision, neither does the player. Does anybody know what I should do?


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    In Hyrule enjoying a chat with Demise and Ganondorf
    My Mood
    Thanked 48 Times in 42 Posts

    Default Re: Tile Collision

    Could you be more specific? What is the program doing incorrectly? How is tiles.get(<int>).collision determined?
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!

    Wanna hear something funny?

    Me too.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,701 Times in 2,651 Posts

    Default Re: Tile Collision

    When you change value of a variable in a loop, its value will be what the last change was. Any previous changes will have been forgotten. Sort of like:
    x = 1;
    x = 4;
    x = 2;

    the 4 and 1 are gone at the last statement.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need help with object collision
    By xDeadScYthe in forum AWT / Java Swing
    Replies: 3
    Last Post: March 23rd, 2012, 07:10 AM
  2. Collision
    By risen375 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 28th, 2011, 07:02 AM
  3. Need help with collision in a game!
    By Skyhigh32 in forum Java Theory & Questions
    Replies: 5
    Last Post: May 18th, 2011, 12:12 AM
  4. Collision Detecting
    By iams3b in forum AWT / Java Swing
    Replies: 0
    Last Post: February 6th, 2011, 01:48 AM
  5. tile map help
    By chuckgod53 in forum Collections and Generics
    Replies: 1
    Last Post: February 10th, 2010, 12:17 PM

Tags for this Thread