Re:A HTML5 game that crashes every browser - browser makers,...
by ehsanu1 on Tuesday October 25, 2011 @11:40AM
(#3154416)
Well, I doubt there would be much of a speed difference when using canvas/drawImage, since I assume "calculating the frame" involves just use some arithmetic on the dimensions of each frame - which is pretty trivial in terms of CPU use at 60fps.
Anyways, you're right, with lots of assets it probably is a much better way to organize sprites into spritesheet. I just never did anything on that scale. 45 animation frames? Sheesh, I'm happy if I can get 5 or 6. :)
I wasn't even aware of using background-image-position as a way to do this... I'll stick that one in my cap, thanks!
I'd say the main benefit of spritesheets as i've seen it would be what you've already commented on: Fewer GETs against the server (when you're thinking in terms of scale, for a large project with lots of assets, i'd say this becomes important, but of course that's a fairly subjective metric), as well as organization of files.
You could go with naming conventions... but then for a 45 frame animation, you have 45 distinct files all named something like "SPECIFIC_ANIMATION_FRAME_X", as opposed to using a dynamic approach, utilizing the cell-size of the frames and the width and height of the image overall, to calculate the frames on the fly; To me, that is far more maintainable than a huge pile of aptly named images.
You could make the claim that calculating out the frame each time is wasted cpu cycles that could be spent elsewhere, but I feel like it's the right approach.
But that could just be my opinion. I would love for someone to weigh in with actual metrics on whether or not using a dynamic approach is actually faster or slower in a meaningful way than a brute-force style naming convention animation system.