SuperSonic wrote:What I know so far is that you have to have a sprite with a rotating animation, a whole toooooooooooon of code
But that's it.
Actually, it only takes one line of code. You just have to have a prerotated sprite as your animation. This is the tricky bit.
The first frame should be 0 degrees (pointing to the right) and it should rotate anti-clockwise from there. Usually, 36 frames of 10 degrees each works well, but for smaller animations, you can get away with 24 frames of 15 degrees. For a larger animation, or one which requires more precision, you might want more (say 72 frames of 5 degrees each).
Depending on how you make your images, this can be easy or more difficult. So if you're using pre-rendered 3d graphics, you can just set up a rotation animation and render it out for each frame. If you're just using an image editor, you'll have to draw it out frame by frame. (with a fancy editor, you could write a script to do it for you. It's also possible to write a script in GE that will load a bitmap and rotate it for you).
Normally I make my graphics in GraphicsGale, which allows me to conveniently add frames to my animation. It also has a rotate function. So I make a whole bunch of frames, and rotate them each the correct amount. A good idea is to make your original image several times larger than the final sprite, then rotate it, then shrink them all down to the proper size - this means you'll get a smoother result.
Once you have the actual sprite done, selecting the correct frame in-game is easy. Just remember to ChangeAnimationDirection to STOPPED on Create Actor. Then in Draw Actor, you adjust the animpos:
- Code: Select all
animpos = (int)round(angle* 0.1)) % 36;
Change angle to be the angle you are facing.
That works for a 36-frame rotation. To adjust the number of frames, you just need to change a few numbers.
The 0.1 should be the number of frames in the animation divided by 360. If this number is going to get to complicated(EG. 24 / 360 =0.066666666...) you can make it a division instead - (angle / 15) - divide by the number of degrees per frame (which is 360 / the number of frames).
Then change the 36 on the end to the number of frames.
And there you have your rotation. Of course, if want to add an animation as well, so that each direction has several frames, this is a littlew more tricky (but not too much). The real challenge is just making all the animations you need.