I tried to hack together a much simplified Arkanoid clone using Raphael in JavaScript. All was well until I tried to set up a fine grained timer to move the ball sprite around the screen. I think it has to be to do with the timeout facility, as updated based on mouse movement are very smooth. Using setTimeout is looked like I was getting max three frames per second. Shame.
Kudos to SpriteLib GPL for making the Arkanoid graphics available. I used this Groovy script to split the images up (copied and pasted from somewhere):import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
BufferedImage bigImg = ImageIO.read(new File("arkanoid.png"));
final int width = 32;
final int height = 32;
final int rows = 19;
final int cols = 13;
BufferedImage[] sprites = new BufferedImage[rows * cols];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
def sprite = bigImg.getSubimage(
i * width + 1,
j * height + 1,
width - 1,
height - 1);
ImageIO.write(sprite, "PNG", new File("sprites/$i-$j.png"));
}
}
Mar 23, 2009
Raphael, SpriteLib GPL, And Timers In JavaScript
Posted
6:08 PM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment