Page 1 of 1

An animation that responds to the mouse?

PostPosted: Mon Aug 02, 2010 9:07 pm
by BloodRedDragon
Hey. Is it possible to have an animation or series of animations that change when the mouse is in a different place? Say you have a turret and a crosshair. the turret changes its animation and faces towards the crosshair, wherever it moves? I have an idea of using several activation regions that follow the actor, but that would be tedious, tiresome and would take up a lot of space, not to mention being a little difficult to program.

Tanks.

Re: An animation that responds to the mouse?

PostPosted: Mon Aug 02, 2010 9:18 pm
by Game A Gogo
The best way to do this is with a single animation containing however many frames you want coming from the angle 0 degree to 360 degree minus one frame. Angle 0/360 starts pointing Right, so your turret would be pointing right, then up, then left, then down, then back right (Minus one frame, we don't need the same position twice). After you have made you animation, you can have this little code in the Draw Actor event to make it point to your cursor, in this example it will be the mouse itself:
Code: Select all
animpos=(direction(x,y,(xmouse-view.width/2),(ymouse-view.height/2))/360)*nframes;

if you want it to follow an actor, this script would be used instead, just replace actor with the actor you want it to point to:
Code: Select all
animpos=(direction(x,y,actor.x,actor.y)/360)*nframes;

What the script does:
Animpos is the current animation frame
direction(x1,y1,x2,y2) gets an angle from 0 to 359
We then divide that angle by 360 so the value ranges from 0 to 1 (Well almost 1!)
Multiply this by the numbers of frame and your animpos will now correspond with your angle!
since we arranged the animation with the angle data, we don't need to change anything else to our angle value :)
I hope this helps!

Re: An animation that responds to the mouse?

PostPosted: Mon Aug 02, 2010 9:23 pm
by BloodRedDragon
Thanks for that. I may make three hundred and sixty animations...... It wont take too long since I'm on summer holidays, but i'm wondering if it'll take up too much space....

Re: An animation that responds to the mouse?

PostPosted: Mon Aug 02, 2010 9:25 pm
by Game A Gogo
Use png's or a GIF

also correction to the first code:
Code: Select all
animpos=(direction(x,y,xmouse+view.x,ymouse+view.y)/360)*nframes;

Re: An animation that responds to the mouse?

PostPosted: Tue Aug 03, 2010 5:09 am
by DilloDude
Generally a 36 frame animation is enough - ten degrees for each frame. For smaller images you can use even less - like 24 frames - 15 degrees. Only for bigger animations do you really need more.

Re: An animation that responds to the mouse?

PostPosted: Tue Aug 03, 2010 9:29 am
by savvy
i made a 100n frame animation, as game_a_gogo will know. and thanks gag, the code works now :D