Subclass of a scene?

CarlFCarlF Posts: 9Member

So, I created a scene for my (2D) game which is a subclass of Sprite. Essentially it's Sprite, with a script added that makes it draggable during play, and emits a signal when it's being dragged (which is used to update a label that shows range to a stationary object on the map). Another object, basically a graphical menu, allows the player to create an instance of this subclass of Sprite, which can then be dragged to a selected location.

Now, the game should have multiple objects with similar behavior (draggable, range displayed by that same label) but not identical. I'd like to subclass this one and then change the things that should be different by overriding methods and properties of Barricade (the first class). Is there provision in Godot to subclass a user-created subclass of one of the built-in classes? Obviously I could just copy the class and change the properties/methods, but then if I tweak the script it becomes a nightmare.

Thanks.

(Side note: I can't add tags to this system, meaning I can't use the tags "subclass" or "class" or "OOP". Is that deliberate?)


Tags :

Answers

  • maroon_carlmaroon_carl Posts: 3Member

    In the "Attach Node Script" window, click the folder to the right of "Inherits" and choose the script you want to inherit. This will put the path to the script in the "Inherits" text field, and when the script is created, it will say extends <path> at the top. You can also change the class name after extends to a script path with quotes around it if you want to change what class it's inheriting from.

  • MegalomaniakMegalomaniak Posts: 1,598Admin

    @CarlF said:

    (Side note: I can't add tags to this system, meaning I can't use the tags "subclass" or "class" or "OOP". Is that deliberate?)

    Yes, that's the way the tags plugin functions.

  • CarlFCarlF Posts: 9Member

    Thank you, both to my namesake and Megalomaniak.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file