What Went Right
This was a
game-jam entry so it was very quick to port over. I had a bit of time left over
from what I budgeted so I decided to add some sounds to the game. The original
game is in space for which there is no sound, but purists can simply turn the
sound off via a nifty sound toggle that I added. The speaker artwork was taken
from another game I wrote that had a sound slider but I didn’t have enough
spare time to try and create a slider, but that is probably something I should
be doing in the future if I ever get enough spare time, which won't be in the next couple of years.
I started
going through some of the public domain and royalty free sounds that I have
collected over the years to find a few sounds that would work with the game. While
some people may not like my choices, I think they work well for the theme of
the game. Sound in Create.js is very easy to play if the files have been
downloaded which I am using preload.js to do so this was trivial to add once
the sound files were found.
What Went Wrong
I went a
bit overboard with the original game and had created a pixel-perfect collision
detection routine. This requires the use of bitmap libraries that Create.js
doesn’t have and would have been very painful to do – not to mention
excruciatingly slow – to do so I reverted to good old-fashioned bounding
circles. The wonderful thing about bounding circles is you just find the
distance squared between two objects and see if the squared distance is within
the combined radiuses. The problem is that if one of the shapes is not
spherical, then the collision results can be a bit inaccurate. I don’t really
mind too much but suspect that I may hear some complaints about this. I did try
to be a bit generous with my circles feeling it is better to have more false
positives than false negatives.
Some of you
may be wondering why I am using distance squared. This is an old-school
technique to save a bit of CPU cycles. Distance is sqrt( (x1-x2)^2 + (y1-y2)^2)
which is a slow routine to calculate since square roots are very slow to
calculate. On the other hand, radius*radius is very fast to calculate so by
forgoing the square root portion of the calculation you can speed up the check
while keeping the accuracy of the calculation.
Mixed Blessings
The
original game used a combination of background images and vector artwork, but I
opted to go with all images even though I could have saved a bit of space by
using some vector images. The tradeoff of a slightly larger file size for
slightly faster game rendering and a easier coding was arguably worth it. The
images I did want to have as vectors were actually fairly large so it wasn’t
that much space that I was using. My original plans were to have the backdrops
converted into a separate jpeg file while the other parts were stored in a png
file so I could get a bit better compression. When using my image view to see
how different compression ratios would affect the image quality, I noticed that
the images looked pretty good when converted to 8-bit png files with only a
small increase in file size so I put all the images into a single image atlas.
For people
who still have slow internet connections, these decisions may have resulted in
longer loading times. For that I apologize as I know most people with slow
internet don’t have a choice in the matter.
No comments:
Post a Comment