An animation that responds to the mouse?

How to find or create sprites, graphics, sounds and music.

An animation that responds to the mouse?

Postby BloodRedDragon » Mon Aug 02, 2010 9:07 pm

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.
Current projects:
Techno-Tank Arena: on hold
Techno-Tank SuperPortal (working title): 0.1%
Bowels of Galaxies: 35% (was a bit too optimistic)
User avatar
BloodRedDragon
 
Posts: 123
Joined: Tue Jan 29, 2008 10:07 pm
Location: The Underworld
Score: 5 Give a positive score

Re: An animation that responds to the mouse?

Postby Game A Gogo » Mon Aug 02, 2010 9:18 pm

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!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: An animation that responds to the mouse?

Postby BloodRedDragon » Mon Aug 02, 2010 9:23 pm

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....
Current projects:
Techno-Tank Arena: on hold
Techno-Tank SuperPortal (working title): 0.1%
Bowels of Galaxies: 35% (was a bit too optimistic)
User avatar
BloodRedDragon
 
Posts: 123
Joined: Tue Jan 29, 2008 10:07 pm
Location: The Underworld
Score: 5 Give a positive score

Re: An animation that responds to the mouse?

Postby Game A Gogo » Mon Aug 02, 2010 9:25 pm

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;
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: An animation that responds to the mouse?

Postby DilloDude » Tue Aug 03, 2010 5:09 am

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

Re: An animation that responds to the mouse?

Postby savvy » Tue Aug 03, 2010 9:29 am

i made a 100n frame animation, as game_a_gogo will know. and thanks gag, the code works now :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


Return to Game Resources

Who is online

Users browsing this forum: No registered users and 1 guest

cron