Results 1 to 8 of 8
Thread: Method not find
- 02-05-2017, 02:05 PM #1
Member
- Join Date
- Feb 2017
- Posts
- 3
- Rep Power
- 0
Method not find
Hello. I am working on a 2D game and I do not know why but from Class1 it cant find method in Class2 but from Class2 can find from Class1.
Here is the code:
Class1:Java Code:import java.util.ArrayList; import org.newdawn.slick.opengl.Texture; import static me.domi.towerdefense.helpers.Clock.*; import static me.domi.towerdefense.helpers.Artist.*; public abstract class Tower implements Entity { private float x, y, timeSinceLastShot, firingSpeed, angle; private int width, height, damage, range; private Enemy target; private Texture[] textures; private ArrayList<Enemy> enemies; private boolean targeted; private ArrayList<Projectile> projectiles; public Tower(TowerType type, Tile startTile, ArrayList<Enemy> enemies) { this.textures = type.textures; this.damage = type.damage; this.range = type.range; this.x = startTile.getX(); this.y = startTile.getY(); this.width = startTile.getWidth(); this.height = startTile.getHeight(); this.enemies = enemies; this.targeted = false; this.timeSinceLastShot = 0f; this.projectiles = new ArrayList<Projectile>(); this.firingSpeed = type.firingSpeed; this.angle = 0f; } private Enemy acquireTarget() { Enemy closest = null; float closestDistance = 10000; for (Enemy e : enemies) { if (isInRange(e) && findDistance(e) < closestDistance) closestDistance = findDistance(e); closest = e; } if (closest != null) targeted = true; return closest; } private boolean isInRange(Enemy e) { float xDistance = Math.abs(e.getX() - x); float yDistance = Math.abs(e.getY() - y); if (xDistance < range && yDistance < range) return true; return false; } private float findDistance(Enemy e) { float xDistance = Math.abs(e.getX() - x); float yDistance = Math.abs(e.getY() - y); return xDistance + yDistance; } public void shoot() { timeSinceLastShot = 0; projectiles.add(new Projectile(QuickLoad("IceShoot"), target, x + TILE_SIZE / 2 - TILE_SIZE / 4, y + TILE_SIZE / 2 - TILE_SIZE / 4, 32, 32, 900, 10)); } private float calculateAngle() { double angleTemp = Math.atan2(target.getY() - y, target.getX() - x); return (float) Math.toDegrees(angleTemp) - 90; } public void update() { if (!targeted) { target = acquireTarget(); } if (target == null || target.isAlive() == false) targeted = false; timeSinceLastShot += Delta(); if (timeSinceLastShot > firingSpeed) /*Here is the error*/ shoot(); for (Projectile p : projectiles) p.update(); angle = calculateAngle(); draw(); }
Java Code:import java.util.ArrayList; public class TowerIce extends Tower { public TowerIce(TowerType type, Tile startTile, ArrayList<Enemy> enemies) { super(type, startTile, enemies); } @Override public void shoot() { System.out.println("Shoot"); super.shoot(); super.getTarget().setSpeed(1); } }
- 02-05-2017, 02:13 PM #2
Re: Method not find
If you are getting error messages, please copy the full text and paste it here.
What is the name of the method(s) that are the problem?If you don't understand my response, don't ignore it, ask a question.
- 02-05-2017, 03:24 PM #3
Member
- Join Date
- Feb 2017
- Posts
- 3
- Rep Power
- 0
Re: Method not find
No there is no error message, bu do not find that Overrided shoot from class2 in class1 in line 82 but it find just hoot method in class1 (line 61)
- 02-05-2017, 03:40 PM #4
Re: Method not find
Can you post the program's output that shows what you are asking about?
Add some comments to the output showing where the output is not what you expected.
shoot from class2 in class1 in line 82 but it find just hoot method in class1If you don't understand my response, don't ignore it, ask a question.
- 02-05-2017, 04:09 PM #5
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Method not find
Line 81 is in the update() method. From where are you calling that method()? The update() method will only call the overridden shoot() method if the containing class of update() is extended and shoot() is overridden there.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 02-05-2017, 04:39 PM #6
Member
- Join Date
- Feb 2017
- Posts
- 3
- Rep Power
- 0
Re: Method not find
Yes update needs to call shootfrom TowerIce but it calls from Tower.
- 02-05-2017, 04:54 PM #7
Re: Method not find
Add some print statements in all the methods that are called, run the program, copy the print out and paste it here.
Add some comments to the print out describing what you are asking about.If you don't understand my response, don't ignore it, ask a question.
- 02-05-2017, 05:08 PM #8
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Method not find
Actually, it would be more helpful if you could construct and post a much simpler example, calling the overridden methods in the same fashion as you do in the actual code. Doing so would better help us help you and it might allow you to discover an error in your program.
Regards,
JimLast edited by jim829; 02-05-2017 at 05:23 PM. Reason: grammar
The JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads
-
Creating a find method to find objects in an array?
By Vetements in forum New To JavaReplies: 3Last Post: 01-28-2017, 04:11 AM -
Cannot find symbol method
By gusten in forum New To JavaReplies: 12Last Post: 04-10-2014, 10:01 PM -
HELP! can't find symbol-method
By Jack9333 in forum New To JavaReplies: 2Last Post: 03-04-2011, 02:48 AM -
Can't find method
By 01allenh in forum New To JavaReplies: 1Last Post: 03-25-2009, 08:46 PM -
Can't find out how to get this method working :)
By Shadaw in forum Java AppletsReplies: 2Last Post: 12-29-2008, 06:35 PM
Bookmarks