Saturday, 5 September 2009

Catch The Birdie

I've started to write a game applet for Solundria using Processing.
My two year old grandson, Ally came up to visit for a week and so I decided to make a game for him.
He is a cheerful little fellow but sometimes quite fearless. He somehow managed to go diving out the backdoor, giving himself quite a nasty black eye. Then he took the doorstop and dropped it on his foot! My glasses went missing for days and then he heroically picked them up from behind a chair and handed them to me.
He went out to play in the back garden and was shouting at the birds to come down, so he could play with them, and so I thought granny would help with that.
One of the problems with writing an applet is that you don't know the size available to the game in the client's browser. I couldn't find an easy way of implementing this, so I just set the size to a default size of 800. I set the height to be 100 pixels smaller than an actual height of 600 to allow for toolbars etc.

Folder Permissions

One of the annoyances of working in Vista is the stifling user permissions. Although I have tried to set the permissions of the processing folder to be not read only, numerous times, it keeps changing them back. This means that every time I export I have to remember to untick read only both in the project folder and the applet folder. If this isn't done I get errors about the images not being found and not being able to delete the applet folder.

Applet Index Page

Every time the project was exported the index page was being overwritten again. This made the background colour, text, width and height of the applet reset to their default values. This was really annoying as I suspect the jar file had a different id number every time it was exported which caused other errors to occur. I was so peeved about having to edit the file every time that I did a search on the Processing site. There I found some great info that means I dont have to do this anymore. There is a file called applet.html in the lib folder of processing. You just need to copy this to your project's root folder and edit it with your preferred values. Now when I export as an applet the index file has the my preferred values and this has saved me a mountain of time!

GifAnimation Library

I made a stop frame animated gif of a birdie using Draw Plus X2. I also made three leaf images, although I'm not very pleased with them. I added these to the sketch folder using Sketch-Add File. I downloaded the Gif Animation library and unzipped it to Processing's Library folder. To use it you just add import gifAnimation.*; to the top of the sketch. I declared it globally as Gif myAnimation; Then to set it with the animated gif and start it off I used:
myAnimation = new Gif(this, "birdie.gif");
myAnimation.loop();
Now it can be drawn anywhere using:
image(myAnimation, xPos , yPos);

The Leaf Class

Adding the Font and Text Dialogs

Mouse Control and State

To be continued....

No comments: