+1 vote

I'm using a script to extend the capabilities of the "AnimatedSprite" node so I can do things like choose special durations to specific frames, or signal when a certain frame of a certain animation is reached. I'll refer to the scripts that defines those methods and signals "Sprite.gd". I also would like to implement in a script attached to the AnimatedSprite node the animations for each individual sprite (player, enemy1, enemy2, etc.), using the methods defined in Sprite.gd.

How can I make so that some AnimatedSprite nodes inherit the methods from my Sprite.gd, while still having a specific script attached to them (e.g.: PlayerAnimation.gd, EnemyAnimation.gd, etc.)? Can I "extends Sprite.gd" or something like that? Or maybe define a new custom node that extends AnimatedSprite and adds my custom methods, and then extend my custom node on the individual sprites?

Thank you :)

in Engine by (22 points)

1 Answer

+5 votes
Best answer

Sure, you just extend by the path

// PlayerAnimation.gd
extends "res://path/to/Sprite.gd"

func _ready():
    pass

KidsCanCode did a tutorial on inheritance in Godot 3.0 earlier this year.

by (91 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.