|
|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Nov 2007
Posts: 18
|
How do i make a cursor that rotates with mouse movements?
Okay, this is what i've managed to do so far:
http://jpoel.byethost15.com/Swim/Swim_example.swf But as you can see it isnt smooth at all! Does anyone have any better code i can use? This is the code i have written to do it: Code:
var px = mouseX;
var py = mouseY;
this.addEventListener(MouseEvent.MOUSE_MOVE,moveMouse);
function moveMouse(e:MouseEvent):void{
var a = mouseY - py;
var b = mouseX - px;
var radians = Math.atan2(a,b);
var degrees = radians / (Math.PI / 180);
Cursor.rotation = degrees;
Mouse.hide();
Cursor.x = mouseX;
Cursor.y = mouseY;
px = mouseX;
py = mouseY;
}
FLA: http://jpoel.byethost15.com/Swim/Swim_example.fla (you might have to right click on that and click "Save target as" |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Nov 2008
Posts: 168
|
That code looks like a good start. The problem is that I can't access your .swf, it just goes to some server notification... this means I can't see what issues you might be having.
The only thing that might need changing is to have Cursor.rotation += degrees as opposed to just "= degrees". If you feel ok about posting your .fla file I'd be happy to have a closer look!
__________________
Check out my blog showing the development of my flash game, the Dregs of War |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Nov 2007
Posts: 18
|
Sorry! try this link:
http://www.swfcabin.com/open/1257616898 as you can see it works, but the mouse's movement is really juttery ;( just need to find a way to make it smoother ALSO: changing = to += made the mouse movements even worse! haha Last edited by JamesPoel; 11-07-2009 at 02:48 PM. |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Nov 2008
Posts: 168
|
it only seems to jitter if I'm going very slowly, because the differences between each frame are greater...
How about instead of just setting the rotation to the dregrees value, you can set a "targetAngle" variable to that, then afterwards you have the cursor rotate towards that angle at a speed you've defined (say 20 degrees per frame). If the difference between the cursor's current angle and the target angle is less than that speed, you just set it's rotation to the target angle. Did that make sense?
__________________
Check out my blog showing the development of my flash game, the Dregs of War |
|
|
|
|
|
#5 | |
|
Junior Member
Join Date: Nov 2007
Posts: 18
|
Quote:
|
|
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Nov 2008
Posts: 168
|
In a tutorial I wrote a while ago, I had an AIPlayer that would rotate a ship to face another ship.
There's a function that figures out what the angle is between the AIPlayer and the its target, then another function (called faceAngle) which will the make the player start turning in that direction. So go here: http://www.flashgametutorials.blogspot.com/ scroll down the AIPlayer class, and find the function faceAngle(), and that could point you in the right direction...
__________________
Check out my blog showing the development of my flash game, the Dregs of War |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Nov 2008
Posts: 168
|
Another idea that could be easier is to have an array which stores the values of the degree variable for the last 5 frames, and have the cursor rotation be the average of those values. that might make for a smoother experience...
[EDIT] Oh and you could try raising the frames per second
__________________
Check out my blog showing the development of my flash game, the Dregs of War |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|