I guess since you are copying code from a video you should do what they do so you can follow along with the video more easily. So a reader of your code would typically expect MyWorld to be a class name (an object type name) and myWorld to be a variable name (an object instance name). But instances of World may or may not also be instances of MyWorld, cast to MyWorld required in order to call methods defined in MyWorld)Īlso, it's standard in Java to start variable names with lower case and class names with upper case. Instances of MyWorld are also instances of World, no cast required. (and casting in that direction isn't required anyway. getCounter() only exists "in" MyWorld type objects. If you have a World base class and a MyWorld class that extends World and the getCounter() method is in the derived MyWorld class, then getCounter() will not be "visible" after you cast a MyWorld type object to a World type object. I know it's frustrating to deal with new people sometimes so I'm sorry in advance.Īny help would be amazing, thanks for reading! I can answer any questions and show more lines if you request. This is the method in question, it is in the MyWorld class: public Counter getCounter() The error is apparently in this line above, here's the error code: "cannot find symbol - method getCounter()". It's in the Food class (the fish, what the shark eats): Actor foodHit = getOneIntersectingObject(Shark.class) I've been having an issue where the program says it can't find a method and I can't seem to figure it out. The user gets a point whenever they eat a fish. void bounce( block) if (getOneIntersectingObject(block)null) Actor ob getOneIntersectingObject(block) move(-moveX,-moveY) int x getX() int y getY() int bx ob.getX() int by ob. I'm making a game where the user controls a shark and has to move around, eating the fish and dodging the trash. The code below does the correct calculations. If you can think of ANY reason as to what may be causing my issue, it's probably worth checking. Before I start, I'd like to mention that I'm new to programming and I'm really bad.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |