Just a quick question. What is a way this could be coded?
Imagine this:
- I have a class called "Monster."
- Class "Werewolf" extends "Monster."
- "Werewolf" has a method called "update()" for updating everything that's in "Werewolf."
- "Werewolf" has a method called "anim()" for animating a walking pattern.
- "Werewolf" has many variables that are used in "anim()." Mainly "Speed."
What I'm trying to do:
- Make it so "anim()" can be moved to "Monster" and still work.
- Make it so "update()" in "Werewolf" contains "{anim();}" but in a way that "anim()" uses the variables in "Werewolf."
What I tried, but didn't work:
- As soon as I moved the method, I noticed I had to fix something with the variables. I can't just put the variables in "Monster" because, sure, werewolves are monsters, but I'm trying to make it so in every subclass of "Monster" I only need to make new variables and call the method "anim()" in some way.
- Someone told me to use "this.*methodNameHere*()" but it doesn't work.
I want to call a method from a superclass in every subclass. The method has a variable "Speed" that is a different value in every subclass. The variable is the same name in every subclass, like this:
Werewolf.Speed
Ghost.Speed
Clown.Speed
And in those subclasses, there's a method "update()." Like this:
Werewolf.update();
Ghost.update();
Clown.update();
I'm not sure how to describe it, but I want those updates to contain "anim()" in a way that this happens:
- Werewolf.update(); calls Monster.anim(); in a way that Werewolf.Speed is used.
- Ghost.update(); calls Monster.anim(); in a way that Ghost.Speed is used.
- Clown.update(); calls Monster.anim(); in a way that Clown.Speed is used.
All I'm trying to do is use a method as a simple framework for animating an animation, keeping the method in a superclass while letting all of its subclasses call the method, while using their own variables/variable values.
So, all I really need is a way to call methods but in some way that the values change. Like Monster.Speed is the basis and the subclass variables of the same name somehow extend that? I don't know.
This thing that I'm trying to do is extremely new to me and I don't know where to go.
Lol I've been stuck on this one problem for 2 weeks.