Okay, so I’ve ventured into my first bit of java programming by making a Tetris clone.
One of the things I wanted to do is make it so the animation was very smooth to make it appear as though the pieces were sliding instead of moving down the grid block by block. I did accomplish this, by running a general animation thread that processes animations for the pieces.
You can take a look at the applet here…
username: guest
password: guest
http://www.grnade.com/tetris/
I’ve attached what my animation thread looks like if anyone wants to see what I mean.
Now heres the thing. I’m ready to add more animation to this to spice it up – you know, effects when you remove a line, perhaps making animations in the background, etc. The thing is my animation thread is going to get cluttered, and it doesn’t really make sense to have just one thread controlling all animations. It’s made timing things a real trick.
I know there is a better way to do this, I’m just looking for some sort of enlightenment here.
I tried giving each animation its own thread object by doing something like this:
Thread animateDrop = new Thread() {
public void run() {
if (yOffset>=20) {
translate(0,1);
yOffset = 0;
} else
yOffset++;
try {
sleep(speed/20);
} catch (InterruptedException e) { }
}
};
animateDrop.start();
The problem with that is objects with threads like that can’t interact with my yOffset variable(the variable that is added in my paint method to give the ‘sliding’ appearance)
So I guess my question is, whats the best way to tackle 2d animation where you could quite possibly have 6 or more animations going on at once? Is there a general consensus here? If anyone even has some good animation programming links, I’d love to see them.