many times i stumble over a problem, which concerns the design of my games.
imaging the following situation:
a game-object, a spaceship (represented by a real java class/object) has e.g. an animation-object for getting the current frame. this animation object should be nothing more than a container for the frames and a counter, which one should be choosed next.
now the anim. can realize a looped animation, a single, a random and so on. so every time something special happens (pressing a key, ship is exploding) the ship sends a signal to the anim. to change the frameset and perhaps the kind of animating.
so far, so beatiful. now my problem:
many times the changing-relationship is reversed:
if the anim. shall animate x-frames and then change to the old frameset, the change depends on the animation, not on the ship.
so there are generally two way of getting the timepoint of changing:
the ship asks every frame, if the animation has expired. this is very elegant an not a good performance choice. but the preoblem is, that the ship-object has access to the animation, but the animation has no to the ship.
so i could give every little tool-object like the animation a reference to its “owner”-object (or perhaps implement the observer pattern). so everyone could send actions to everyone.
this would solve my problem, but i think that this would be terrible coding style.
