To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Actionscript 3.0

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 11-07-2009, 08:02 AM   #1
JamesPoel
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"
JamesPoel is offline   Reply With Quote
Old 11-07-2009, 11:22 AM   #2
Awoogamuffin
Senior Member
 
Awoogamuffin's Avatar
 
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
Awoogamuffin is offline   Reply With Quote
Old 11-07-2009, 02:41 PM   #3
JamesPoel
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.
JamesPoel is offline   Reply With Quote
Old 11-07-2009, 02:55 PM   #4
Awoogamuffin
Senior Member
 
Awoogamuffin's Avatar
 
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
Awoogamuffin is offline   Reply With Quote
Old 11-07-2009, 02:58 PM   #5
JamesPoel
Junior Member
 
Join Date: Nov 2007
Posts: 18
Quote:
Originally Posted by Awoogamuffin View Post
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?
haha that didnt make much sense at all im afraid :$ im a bit noobish with AS3 when it gets to a certain depth, could you point in the right direction with some code or something?
JamesPoel is offline   Reply With Quote
Old 11-07-2009, 03:01 PM   #6
Awoogamuffin
Senior Member
 
Awoogamuffin's Avatar
 
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
Awoogamuffin is offline   Reply With Quote
Old 11-07-2009, 03:42 PM   #7
Awoogamuffin
Senior Member
 
Awoogamuffin's Avatar
 
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
Awoogamuffin is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Actionscript 3.0

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:05 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.