Results 1 to 9 of 9
- 05-28-2011, 10:53 AM #1
Member
- Join Date
- May 2011
- Posts
- 12
- Rep Power
- 0
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:
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:if(comCart.getPosition().intersects(dropCreate.getPosition())){ dropCreate.getPosition().x = 544; dropCreate.getPosition().y = 0; stillNeed.gotIn(); }
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.Java Code:public Rectangle getPosition() { return pos; }
- 05-28-2011, 11:48 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
What result do you get when you print the return of the intersect method shown in that if?
- 05-28-2011, 11:59 AM #3
Member
- Join Date
- May 2011
- Posts
- 12
- Rep Power
- 0
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.
- 05-28-2011, 12:04 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
- 05-28-2011, 12:12 PM #5
Member
- Join Date
- May 2011
- Posts
- 12
- Rep Power
- 0
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
- 05-28-2011, 12:32 PM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Java Code:System.out.println(comCart.getPosition().intersects(dropCreate.getPosition()));
- 05-28-2011, 12:38 PM #7
Member
- Join Date
- May 2011
- Posts
- 12
- Rep Power
- 0
yea put that in. No println happened in dos. for some reason the objects are not interacting, sorta guessed that in the first place.
- 05-28-2011, 12:47 PM #8
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
- 05-28-2011, 12:54 PM #9
Member
- Join Date
- May 2011
- Posts
- 35
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks