
November 16th, 2006
06:00 AM
Neverside Newbie
Status: Offline!
Javascript: Rotating an iage by mouse movement.
I was wondering if anybody knew how to do this:
Let's say I have an image top-down view of a person standing. This person has eyes and arms. When I move the mouse around him in a circle the person will rotate to face my mouse cursor. The image will not move x or y position at all, just rotate. I want this for a simple shooting game i'm working on in javascript where you move the person with keyboard events and you aim through mouse cursor and shoot by mouse click. I'd like to have the person always face towards mouse cursor. If anyone can help thanks.
___________________
Click here to email me!

November 16th, 2006
07:02 AM
I need a haircut
Status: Offline!
JavaScript can't rotate pictures. I don't think.
You could fake it using a set of images that depict your guy in different positions of rotation (or a composite sprite thereof)., maybe at 45 or 30 degree intervals [edit: Flash could do this portion much easier]. Then you'd have to do some trigonometry + JavaScript magic to detect what angle the mouse cursor is at.
I'll take a stab at this out of curiosity..
___________________
Jon Culver Chia Pets
Last edited by sparky, November 16th, 2006 07:04 AM (Edited 1 times)

November 16th, 2006
07:43 AM
I need a haircut
Status: Offline!
Hooray for high school math
Save & run them both together or you'll be a little confused.
___________________
Jon Culver Chia Pets

November 16th, 2006
07:50 AM
Neverside Newbie
Status: Offline!
Wow thanks buddy! Yeah I found a simple image rotation thing on javascript where you can rotate an image by angle but all I need is this script to use to determine that angle. Wow! Thanks a lot!!!!
___________________
Click here to email me!

November 16th, 2006
08:04 AM
Neverside Newbie
Status: Offline!
Maybe you can help me out with another problem also. I have the keydown and keypress event working in javascript but there was always a problem I had before when using java, now in javascript I am having the same problem. I am wondering how it's possible to hold down two keys at once and detect both of them. For instance, in the game the character moves up, down, left, and right but each time you press one button he'll move and then stop for 1 sec to go the next direction when you hit a new button. If you hit for ex: down and right together he'll go either just down or just right. What I am wondering is how it's possible to make him move both down and right (pressing both down and right buttons on keyboard) at the same time using the keydown/keypress event.
___________________
Click here to email me!