I have a class that needs to use the graphics methods of the Sprite class, so I’ve extended said class using Sprite. However I have my own custom class that the first class ALSO needs to extend from to use the properties and methods written within.
Of course I could extend my custom class by Sprite and the first class would be able to use both, but my custom class has nothing to do with Sprite and shouldn’t extend it.
How would I go about using the properties and methods of my custom superclass AND use the graphics properties of the Sprite class in one subclass?
My simple example:
My custom class is named MovingObject.as and contains two variables and some methods that need to be inherited by a subclass. The purpose of MovingObject is to hold information relating to the speed and acceleration of their child classes.
The child class ‘RaceCar’ is drawn using the graphics methods given by expanding Sprite, but I need to expand from MovingObject allowing the RaceCar to inherit speed and acceleration.
I’m stuck on how to both give RaceCar the features of expanding from Sprite and my MovingObject class.
If your first class needs to be added to the display list it should almost certainly extend
Sprite. How you make the functionality of your second custom class available to it will probably depend on what that functionality is (if you could give a brief description it would make answering the question much easier).However, in addition to extension (which you’ve ruled out), I can think of two other methods:
Update:
I think you might be complicating things unnecessarily in this case, unless you envisage having sub-classes of
MovingObjectwhich are not visually represented on screen (which seems unlikely to me). If not, it’s perfectly valid forMovingObjectto extendSprite, in effect augmenting it with moving functionality, and this forming the base class for yourRaceCar(and any other moving, visible objects).