I want to create a ball class with a number of layers, which can be combined in multiple ways and also act as a physics object. There will be:-
-
a base layer (a circle display object) which is plain coloured. This circle should also act as the physics body.
-
a pattern layer (a bitmap with transparency) that should simply track the base layer (both position and rotation)
-
a top layer (another bitmap with transparency) which acts as a “shine” texture for the ball and which should not rotate with the ball
So far, the best I can seem to do to achieve this is to make sure all my instances of the ball are contained in a table and then have an enterFrame listener which loops through the table and runs a class “sync” method that aligns the position and rotation of layer 2 with layer 1, and aligns just the position of layer 3 with layer 1.
I really dislike using this sort of looping method because it makes it more difficult to remove objects from the table when they’re no longer needed (not impossible I know, just inelegant). I would really like for my class instances to be self-contained. Is there a more elegant way to do this that I’m missing?