Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my class, I extend Sprite class. I override one of the method collideWith(). But my problem was that when current sprite collide with other sprite it does not call the call back method collideWith(). Here is my implementation.

public boolean collidesWith(IShape pOtherShape) {
    System.out.println("collide with called");
    return true;

Any member please help me.

share|improve this question
up vote 1 down vote accepted

This is not a callback, you have to call the method yourself to find out whether the Sprites collide. By overriding it you broke its functionality. What you want to do (I think) is override the onUpdate method of the Sprite and put there an if statement calling the collidesWith(otherSprite) method.

share|improve this answer
So what it the advantage to override this method in out user define class. – Siddharth Oct 2 '12 at 8:20
There is no reason to override the method collidesWith unless you want to handle the collision checking all by yourself. Overriding onUpdate is just the way of achieving what you want, it will run user-defined code on every step and you're free to do whatever you want with it. Just make the body of onUpdate slim, because this code will run very often and could slow down you application. – JohnEye Oct 2 '12 at 8:26
If you override a method, you redefine his behavior. By overriding, you redefine (i suppose) the collision detection process. In java, you can use the "super" operator and do something like super.collideWidth(...) – nathan Oct 2 '12 at 8:36

Just to clarify a bit.

First read about about callbacks.

If you have to call it yourself, it's probably not a callback.

In java, you can override a method (maybe you should read about OO concepts) like you did:

public void foo() {

The method foo is override in a custom class that probably extends another class (or implements an interface but in this case you have to override all the methods of the interface since they are abstract. Read more about interfaces here.) that contains a foo method itself.

class ParentClass {

    public void foo() {
        //do something

Since overriding a method mean "redefining" his behavior, if you call the foo method from your custom class extending ParentClass it will (in this case) not do anything. If you want to reach a method from a parent class, use super.

public void foo() {; //will call the foo method of the parent class
    //add custom code here

Also you should read this great tutorial covering inherence in Java:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.