MCG
Smash Apprentice
- Joined
- Nov 11, 2013
- Messages
- 95
Thanks. I'll look this up. I think the biggest disadvantage is going to be performance.Nothing in javascript is ever guaranteed, and that's especially true for timers. They'll fire when they'll fire. Also, you aren't pre-loading the frame images, so loading times could mess/are messing with the timing, too. Load times with local files shouldn't be an issue, but you never know. A good thing to do is to keep tract of your deltas between frames (really, between your setInterval fires), and then use that value to frame skip or wait if necessary. Here is like a really basic guide with some code snippets. Not the best solution, but that's what you give up for having frame control and running in any web browser. As a fall back, you could just have a GIF/aPNG that ran at the proper 60 fps for the 1x speed, and transition to the animated jpgs when people want to use the controls/change speed etc. (btw, can you set FPS in gifs? I don't really know. Maybe that's why the speed looks off for Sangoku)
Anyways, this looks like a good start! I've been wanting to write up something like this for a while (to learn how to use canvas to animate, play around with timers, etc.) but I've been really busy at work so I never got around to it. For the transparency, you could probably just use css opacity on the hitbox image and let the client handle the mixing between the non-hitbox and hitbox images. This assumes that characters are positioned in the exact same spot on the two images, though.
I did some tests for transparency and it's working but it's even more sluggish at higher speed. x0.25 and x0.33 it's decent. I'll tweak it a bit and have normal mode, hitbox mode and both modes.