Rotating sprites?

Non-platform specific questions.

Rotating sprites?

Postby SuperSonic » Wed Sep 29, 2010 5:25 pm

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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Rotating sprites?

Postby DilloDude » Thu Sep 30, 2010 2:25 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: Rotating sprites?

Postby SuperSonic » Fri Oct 01, 2010 12:02 am

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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Rotating sprites?

Postby DST » Fri Oct 01, 2010 1:10 am

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).
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Rotating sprites?

Postby SuperSonic » Fri Oct 01, 2010 2:26 am

Thank's dude :D
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Rotating sprites?

Postby savvy » Fri Oct 01, 2010 6:13 pm

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
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: Rotating sprites?

Postby SuperSonic » Sat Oct 02, 2010 1:03 am

Thanks Savvy :D
I'll try your code when I have some time(Probably saterday) :D
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest