set collision between player and 2d array ground

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • game2d
    New Member
    • Apr 2013
    • 59

    #1

    set collision between player and 2d array ground

    collision between player and ground

    Code:
    public void levelWCollision(Player p)
    	{
    	for(int i = 0; i < rect.size(); i++)
    {
          if(p.getBounds().intersects(this.rect.get(i))){
               flag = true;
              break;
          }
        else
           flag = false;
    }
    }
    	System.out.println(flag);
    if(flag )
       System.out.println("hi");
    else
    System.out.println("bye");
    
    }
    flag prints:
    true
    false
    false
    false
    ...

    it should prints true, true, true, true, true, bc player is touching the ground rect from arraylist.
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    I've said this in a previous post: Without seeing the "intersects " method it's nearly impossible to tell, why this isn't working. Is it a predefined method from a library? Is it something you wrote yourself? How does it work? Also, what kind of Object does "p.getBound s()" return and what is rect an ArrayList of?

    Comment

    Working...