Parent-child appearance and animation differences?

I understand the idea of inheritance, eg that if Parent contains a “Run and jump” behavior, the Child does too (even though you can’t see it).

However, can I have a Main Player Character object as a parent with a run and jump behavior and Main Character animation, and then start another level with a Child character with the same inherited behavior but different appearance?

And if so, how would I change the animations for it without affecting the Parent character?

I’ve been thinking of ways to approach a game where the character is wearing different clothes in each level, and has different abilities (shooting, horseriding, etc) for each level, but the fundamental walking, jumping, inventory logic stays the same in each.

Or are Parent/Child things a stupid way of doing this?

Have been thinking of different ways of using inheritance but each time I come across the issue of “I want the child to have the same logic as the parent except for this detail” and that seems tricky. I guess it’s most useful if you have a base enemy type which kill you if you touch them, and then some enemies can shoot fireballs, others can explode, etc? But then you get back to the issue of them each having a different appearance and animation as they move around?

Sorry, I think my backround in other code may be messing up my thinking, and it’s probably dead simple :sweat_smile:

I’m pretty sure child objects can have their own sprites and animations. Parents only affect the code of the object.

The animations are called in the code though? Or would I just call the new animation the same thing? (like “Enemy Walk”

Yeah, I believe if you call it the same thing, it will call the animation. Just be sure to add new animations for every Child object.

1 Like