Results 1 to 9 of 9
  1. #1
    Grid_iso is offline Member
    Join Date
    May 2011
    Posts
    12
    Rep Power
    0

    Default help with intersects() and contains()

    My code compiles is fine except that the intersects method (I have also tried it as a contains method) does not act or something.
    Here it is:
    Java Code:
    		if(comCart.getPosition().intersects(dropCreate.getPosition())){
    			dropCreate.getPosition().x = 544;
    			dropCreate.getPosition().y = 0;
    			stillNeed.gotIn();
    		}
    this is within my action performed method and should worth with all the rest of what I've written. Basically what is should do is if the create hits the cart then it re-positions itself and a number goes down but none of that happens. to gain the positions that are always changing I use this code:

    Java Code:
    	public Rectangle getPosition() {
    		return pos;
    	}
    it works in another part of this program so I don't think it's that though. Any help or suggestions would be much appreciated. I have looked around for examples on this kind of stuff what they are all written in the same classes so it's easier for them to refer to things and looks different to how I need to write it... I think any way.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    What result do you get when you print the return of the intersect method shown in that if?

  3. #3
    Grid_iso is offline Member
    Join Date
    May 2011
    Posts
    12
    Rep Power
    0

    Default

    that return statement of pos? it just gives me access to the pos Rectangle I have in that class. I don't fully understand what you are trying to say but nothing prints this is a game not text based. it had Jpanels and JFrames etc.

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You still show a conditional in your first snippet, and I am assuming it returns something, try printing the return value of the statement being used as the condition to the first snippet. This will help you debug the problem.

  5. #5
    Grid_iso is offline Member
    Join Date
    May 2011
    Posts
    12
    Rep Power
    0

    Default

    Can you please write an example of what you mean? Sorry i can easily miss what people mean with this type of stuff a lot

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Java Code:
    System.out.println(comCart.getPosition().intersects(dropCreate.getPosition()));

  7. #7
    Grid_iso is offline Member
    Join Date
    May 2011
    Posts
    12
    Rep Power
    0

    Default

    yea put that in. No println happened in dos. for some reason the objects are not interacting, sorta guessed that in the first place.

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Without any code it's hard to tell you anything, most people will only really guess with what little code you have supplied. As of right now I have no idea when the code snippet is called, if it's called, etc.

  9. #9
    jing-yi is offline Member
    Join Date
    May 2011
    Posts
    35
    Rep Power
    0

    Default

    Hi,

    can you provide your code to us? (If not all, please provide at least this whole class), so we can help you.

    Thanks
    Jing-yi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •