Basic java question I have playerGamestate which extends DefineGamestate which extends Gamestate
in Gamestate thier is an abstract update method in an attempt to clean up playerGamestate I initialized the update method in DefineGamestate however i'm having an issue making the playerGamestate update method update after i do so
Can anyone enlighten me?
What's the issue :?
well i guess this is an issue of overriding methods.
in Gamestate the update() method is abstract, which means that each class which extends Gamestate has to implement the update() method.
As i get it, you have done this in your DefineGamestate.
So you have your basic implementation with some functionality, and now you extend this class by your class PlayerGamestate.
In there you have to override the DefineGamestate’s update() method to add some new or alter the functionality it contains.
To override a method of a parent class, the new method has to have the same method-signature (visibility, returntype, name, parameters), else java doesn’t detect that it should call this method instead of the parent’s one.
And then you have to choose what you would like to do inside this method.
Example:
Gamestate’s update:
public abstract void update (float time);
DefineGamestate’s update:
public void update (float time){
System.out.println("DefineGamestate’s update());
}
PlayerGamestate’s update:
public void update (float time){
//super.update(time) //this will call the parent’s update() first
System.out.println("PlayerGamestate’s update());
}
hope i got what your problem is, else try to give some more information
greetz
yes actually you did so by calling
super.update(tpf) in the update method of the playerGamestate I will be able to run everything through the one update method
Okay thank you exactly what i was trying to figure out
ok, glad to help!
what i tried to explain was, that if you want to run some additional functionality (which is independet of the functionality in the super.update(tpf) ) you can add it after the super.update(tpf) call.
But if you want to alter the functionality which would be run in the super.update(tpf), you have to copy the code into your child class and alter it there. If you do so, don't call super.update(tpf).
but this approach isn't that sexy/clean