00:00
00:00
Newgrounds Background Image Theme

VolublePally just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: mouse speed

3,676 Views | 19 Replies
New Topic Respond to this Topic

AS: mouse speed 2007-04-22 21:36:35


AS: main

ever wonder how to make a throwing game or track the speed of the mouse??
i diddnt see a tutorial on this,so im writing up my own :D

to start off make an _x array and a _y array
so you should have somthing like this in the frame

xar = new Array()
yar = new Array()

now what you need to do is create a variable to increase every frame,like this

var i:Number=0

so now we will increase that every frame like this

onEnterFrame=function(){
i++
}
now we will start with the xmouse

onEnterFrame=function(){
i++
xar[i]=_xmouse
xx=xar[i]-xar[i-1]

}

now,all this does is,add a value to xar

our _xmouse variable

every frame then it gets the distance between that value and the previouse value

sofar we have this

xar = new Array()
yar = new Array()
var i:Number=0
onEnterFrame=function(){
i++
xar[i]=_xmouse
xx=xar[i]-xar[i-1]
}

and for the _ymouse values just add
yar[i]=_ymouse
yy=yar[i]-yar[i-1]

and that does the same thing but with the _ymouse

now are compleate code is

xar = new Array();
yar = new Array();
var i:Number = 0;
onEnterFrame = function () {
i++;
xar[i] = _xmouse;
xx = xar[i]-xar[i-1];
yar[i] = _ymouse;
yy = yar[i]-yar[i-1];

};

see,this is useful beacuse with this you can
throw objects
slide objects
and other cool stuff

example:
http://denvish.net/ulf/220407/77642_throw.fla
http://denvish.net/ulf/220407/77666_throw.php

the fla and the swf

feel free to use the code as shown

Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: mouse speed 2007-04-22 21:54:43


wow nice. to bad denvish doesn't update as:main much anymore.

Response to AS: mouse speed 2007-04-22 22:00:09


nice, although i already knew how to do it you can use the principles of that code to do anything like finding how fast an object is rotating, nice work!

Response to AS: mouse speed 2007-04-22 23:07:42


its good in theory, but try dragging the ball over to the left, waiting, then dragging it back to the center and then try and throw it. Maybe if you cleared some of the data after 3 seconds or so.
Nice job though

Response to AS: mouse speed 2007-04-24 07:18:03


At 4/22/07 11:07 PM, LesPaulPlayer wrote: its good in theory, but try dragging the ball over to the left, waiting, then dragging it back to the center and then try and throw it. Maybe if you cleared some of the data after 3 seconds or so.
Nice job though

thanks,i forgot to post the set interval function to remove variables :/
but i do wish denvish would update more >:U


Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: mouse speed 2007-04-24 07:24:21


At 4/22/07 11:07 PM, LesPaulPlayer wrote: its good in theory, but try dragging the ball over to the left, waiting, then dragging it back to the center and then try and throw it. Maybe if you cleared some of the data after 3 seconds or so.
Nice job though

actually,i diddnt find a glitch and all that removing the data would do is remove a tiny little bit of lag :/
but i might just make a new thread with that in it :D


Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: mouse speed 2007-04-24 07:30:02


Why store all the values in an array?

prevX=prevY=0;
onEnterFrame=function(){
xDist=_xmouse-prevX;
yDist=_ymouse-prevY;
prevY=_ymouse;
prevX=_xmouse;
}
Much easier, less lag. Good tut nonetheless, Well structured, well explained.


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

Response to AS: mouse speed 2007-04-24 07:48:44


thanks vengence,i just diddnt see anything on mouse speed so i made one :D
and i guess i diddnt have to use arrays but incase you wanted it to be able to see past mouse speeds i used arrays :D
but i wish there was an edit post function >:U


Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: mouse speed 2007-04-24 07:49:20


oh wow thats awesome.. Thanks!!!

Response to AS: mouse speed 2007-04-24 15:16:03


At 4/22/07 09:54 PM, ShittyFlash wrote: wow nice. to bad denvish doesn't update as:main much anymore.

AS: Main is locked, that's why. Also, nice tut.


01000100011000010110111001100011011 01001011011100110011101010000011010 01011011100110010101100001011100000 11100000110110001100101010001110111 010101111001

BBS Signature

Response to AS: mouse speed 2007-04-24 15:30:35


At 4/24/07 03:16 PM, salted-tator-tot wrote:
At 4/22/07 09:54 PM, ShittyFlash wrote: wow nice. to bad denvish doesn't update as:main much anymore.
AS: Main is locked, that's why. Also, nice tut.

thanks,but AS: main has been unlocked for about a month now :D


Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: mouse speed 2007-04-24 16:58:53


i swear to god two hours ago i was thinking. Man i want to know mouse speed for a throwing game, but i don't know which tutorial to use.

:P thanx

Response to AS: mouse speed 2007-04-24 17:11:00


At 4/24/07 07:30 AM, Vengeance wrote: Why store all the values in an array?

Thats what I was thinking. You also should have included pythagorus to work out the direct distance.

But it was good, anyways.

Response to AS: mouse speed 2007-04-25 07:15:28


ok,maby i could have made it simple >:U
but im known for overcomplicating the simple stuff :D
but i found this way much more fun :D


Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: mouse speed 2009-03-28 06:38:34


over coplicated not? i just quickly invented this code, and it works great
onEnterFrame = function ()
{
xspeed = Math.abs(_xmouse-mousex);
yspeed = Math.abs(_ymouse-mousey);
mousespeed = Math.sqrt((xspeed*xspeed)+(yspeed*yspeed ));
mousex = _xmouse;
mousey = _ymouse;
};

mosespeed is the mousespeed


AS2||AS3||Motox

Thanks to hdxmike for the sig :]

BBS Signature

Response to AS: mouse speed 2009-03-28 09:16:49


What's the point of the Math.Abs? Squaring / squarooting nullifies it.

Response to AS: mouse speed 2009-03-28 23:54:08


At 3/28/09 09:16 AM, StaliN98 wrote: What's the point of the Math.Abs? Squaring / squarooting nullifies it.

point taken


AS2||AS3||Motox

Thanks to hdxmike for the sig :]

BBS Signature

Response to AS: mouse speed 2009-03-29 02:33:12


At 3/28/09 11:54 PM, Yambanshee wrote:
At 3/28/09 09:16 AM, StaliN98 wrote: What's the point of the Math.Abs? Squaring / squarooting nullifies it.
point taken

.....Wth? Math.Abs does have a big point. It's absolute value, which means, it makes the inside value positive. It's also faster (and more efficient) than

Math.sqrt(Math.pow(16,2));

Yam., Why did you bump this thread?

Response to AS: mouse speed 2009-03-29 04:55:18


At 3/28/09 06:38 AM, Yambanshee wrote: over coplicated not? i just quickly invented this code, and it works great
onEnterFrame = function ()
{
xspeed = Math.abs(_xmouse-mousex);
yspeed = Math.abs(_ymouse-mousey);
mousespeed = Math.sqrt((xspeed*xspeed)+(yspeed*yspeed ));
mousex = _xmouse;
mousey = _ymouse;
};

mosespeed is the mousespeed

This would be tidier if you replaced "xspeed*xspeed" with "xspeed^2"

And I also think you don't need the abs in this case, as has been said.


BBS Signature

Response to AS: mouse speed 2009-03-29 05:35:52


At 3/29/09 04:55 AM, Hoeloe wrote:
At 3/28/09 06:38 AM, Yambanshee wrote: over coplicated not? i just quickly invented this code, and it works great
onEnterFrame = function ()
{
xspeed = Math.abs(_xmouse-mousex);
yspeed = Math.abs(_ymouse-mousey);
mousespeed = Math.sqrt((xspeed*xspeed)+(yspeed*yspeed ));
mousex = _xmouse;
mousey = _ymouse;
};

mosespeed is the mousespeed
This would be tidier if you replaced "xspeed*xspeed" with "xspeed^2"

And I also think you don't need the abs in this case, as has been said.

"xspeed^2" won't work (at least with AS 2.0). You should use "Math.pow(xspeed, 2)"


Applejuice ftw

BBS Signature