This site requires JavaScript, please enable it in your browser!
Greenfoot back
CHERNANDEZ95
CHERNANDEZ95 wrote ...

2013/2/17

getIntersectingObject

1
2
3
4
CHERNANDEZ95 CHERNANDEZ95

2013/2/17

#
Would greatly appreciate some help with this assignment. My instructions are to Create a method called getIntersectingOrb(). When invoked, it should return the Orb object that intersects with the current Orb. If there is no intersecting Orb, it returns null. This is what I have: private Actor getIntersectingOrb() { Actor orb = getOneIntersectingObject(Orb.class); if(orb != null) { return (orb) getOneIntersectingObject(Orb.class); } } Ii keep getting "missing return statement"
danpost danpost

2013/2/17

#
You do not need an 'if' statement at all. 'getOneIntersectingObject' will either return an object of supplied type or null. Just retun 'orb'.
CHERNANDEZ95 CHERNANDEZ95

2013/2/17

#
I am a beginner at all this. My instructor told us to follow the example in the book, which uses an if statement using null. With your suggestion, I came up with this: private Actor getIntersectingOrb() { Actor orb = getOneIntersectingObject(Orb.class); return (Orb) getOneIntersectingObject(Orb.class); }
CHERNANDEZ95 CHERNANDEZ95

2013/2/17

#
I am almost certain it is wrong, but I appreciate your patience and you sharing your knowledge.
danpost danpost

2013/2/17

#
You already have a reference to the intersecting Orb object in 'orb'. I think the way you have it now will work, but since 'orb' is never used after it is assigned a value, that line can be removed (or change the line after it to 'return orb;'.
danpost danpost

2013/2/17

#
One thing you might consider is that the assignment asks for it to return an Orb object (not an Actor object). Adjust your code to fill this requirement.
CHERNANDEZ95 CHERNANDEZ95

2013/2/17

#
ok, how about this one? private Actor getIntersectingOrb() { return (Orb) getOneIntersectingObject(Orb.class); } It compiled....
CHERNANDEZ95 CHERNANDEZ95

2013/2/17

#
Ok, so something along the lines like: private Orb getIntersectingOrb() { return (Orb) getOneIntersectingObject(Orb.class); }
danpost danpost

2013/2/17

#
Looks good!
CHERNANDEZ95 CHERNANDEZ95

2013/2/17

#
Awesome! Thank you sooooooo much danpost. : )
AngelusNeko13 AngelusNeko13

2015/10/21

#
umm guys can u help me with making collisions happen with cars?
danpost danpost

2015/10/21

#
AngelusNeko13 wrote...
umm guys can u help me with making collisions happen with cars?
Please start a new discussion thread. Show attempted code. Ask about specific problems you are having (not general ones). About the only help you would get with what you have given is something like this:
anyone wrote...
Look at the Actor class API documentation and determine what methods might help with your issue.
AngelusNeko13 AngelusNeko13

2015/10/21

#
well heres my code and nothing happened when the car touched the traffic
1
2
3
4
5
6
7
8
9
10
11
12
13
public void checkCollision()
  {
       
     Actor Car = getOneIntersectingObject(Vehicle.class);
       
      if(Car != null)
       
      {
          Greenfoot.playSound("crash.wav");
          Greenfoot.stop();
           
      }
  }
AngelusNeko13 AngelusNeko13

2015/10/21

#
btw sorry im a begginer at this
danpost danpost

2015/10/21

#
AngelusNeko13 wrote...
well heres my code and nothing happened when the car touched the traffic < Code Omitted >
The code seems appropriate. It should be in your Car class and it should be called from the act method of that class.
There are more replies on the next page.
1
2
3
4