By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,654 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,654 IT Pros & Developers. It's quick & easy.

set collision between player and 2d array ground

P: 59
collision between player and ground

Expand|Select|Wrap|Line Numbers
  1. public void levelWCollision(Player p)
  2.     {
  3.     for(int i = 0; i < rect.size(); i++)
  4. {
  5.       if(p.getBounds().intersects(this.rect.get(i))){
  6.            flag = true;
  7.           break;
  8.       }
  9.     else
  10.        flag = false;
  11. }
  12. }
  13.     System.out.println(flag);
  14. if(flag )
  15.    System.out.println("hi");
  16. else
  17. System.out.println("bye");
  18.  
  19. }
  20.  
flag prints:
true
false
false
false
...

it should prints true, true, true, true, true, bc player is touching the ground rect from arraylist.
May 8 '13 #1
Share this Question
Share on Google+
1 Reply


Nepomuk
Expert 2.5K+
P: 3,112
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.getBounds()" return and what is rect an ArrayList of?
May 16 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.