Page 1 of 1

Rotating sprites?

PostPosted: Wed Sep 29, 2010 5:25 pm
by SuperSonic
I know it's possible, because i've seen people do it, but I just can't figure out how to make a sprite that can rotate. :(
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. :(
Help is much appritiated. :D Thank you

Re: Rotating sprites?

PostPosted: Thu Sep 30, 2010 2:25 am
by DilloDude
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.

Re: Rotating sprites?

PostPosted: Fri Oct 01, 2010 12:02 am
by SuperSonic
I don't want to sound ungratefull(cus I'm not :D ), but I can't really understand your code :(
Is there any way for you to make it a little more simple :?
If you can't, that's fine. I'll keep trying to figure it out but I'm still VERRRRY new to scripting. :roll:
anyways thanks allot :D

Re: Rotating sprites?

PostPosted: Fri Oct 01, 2010 1:10 am
by DST
Go here to get Feral's Sprite Maker Beta for GE (it's made with GE!!!)

viewtopic.php?f=4&t=5869&start=0&hilit=sprite+maker+beta

The instructions are self-explanatory. Uses 24-bit bmp format.

Your starting frame should always face right (that's 0 degrees).


Usage:

Code: Select all
animpos=angle/(360/nframes);


Angle always exists for any actor, no matter how you made it happen(directional_velocity, xvelocity, x+=, moveto();) Angle is a constant and is always active. Nframes is also a constant, designating Number of Frames (in animation currently assigned).

Re: Rotating sprites?

PostPosted: Fri Oct 01, 2010 2:26 am
by SuperSonic
Thank's dude :D

Re: Rotating sprites?

PostPosted: Fri Oct 01, 2010 6:13 pm
by savvy
then if you want it to rotate to another actor do:

angle=direction(x,y,actor.x,actor.y); animpos=(angle/360)*frames;

if you want the actor to move in the direction of the animation do:

angle=animpos*360/frames; directional_velocity=10; (10 being the speed)

there's a ton of stuff :D

Re: Rotating sprites?

PostPosted: Sat Oct 02, 2010 1:03 am
by SuperSonic
Thanks Savvy :D
I'll try your code when I have some time(Probably saterday) :D