I have made two classes that allows me to cut a BufferedImage into pieces, and apply a direction and speed to them. I use that to make sprites explode when the character dies. However I have no idea how to add gravity to them. So far the pieces just float off into any direction instead of falling down to the bottom of the screen.
My very simple code
[quote]layer.setX(layer.getX() + Math.sin(layer.getDirection()) * layer.getSpeed());
layer.setY(layer.getY() + Math.cos(layer.getDirection()) * layer.getSpeed());
[/quote]
The “layer” object have a getPixelCount() method, which returns the amount of none fully transparent pixels in the image, which is what I was going to use to add different weight to the pieces.