Be a Supporter!

AS: mouse speed

  • 2,555 Views
  • 19 Replies
New Topic Respond to this Topic
EvanHayes
EvanHayes
  • Member since: Jan. 13, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
AS: mouse speed Apr. 22nd, 2007 @ 09:36 PM Reply

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.

ShittyFlash
ShittyFlash
  • Member since: Apr. 13, 2007
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to AS: mouse speed Apr. 22nd, 2007 @ 09:54 PM Reply

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

MattPrior
MattPrior
  • Member since: Mar. 27, 2006
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: mouse speed Apr. 22nd, 2007 @ 10:00 PM Reply

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!

LesPaulPlayer
LesPaulPlayer
  • Member since: May. 18, 2006
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: mouse speed Apr. 22nd, 2007 @ 11:07 PM Reply

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

EvanHayes
EvanHayes
  • Member since: Jan. 13, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: mouse speed Apr. 24th, 2007 @ 07:18 AM Reply

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.

EvanHayes
EvanHayes
  • Member since: Jan. 13, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: mouse speed Apr. 24th, 2007 @ 07:24 AM Reply

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.

Vengeance
Vengeance
  • Member since: Mar. 18, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to AS: mouse speed Apr. 24th, 2007 @ 07:30 AM Reply

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
EvanHayes
EvanHayes
  • Member since: Jan. 13, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: mouse speed Apr. 24th, 2007 @ 07:48 AM Reply

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.

MattLutton
MattLutton
  • Member since: Sep. 26, 2005
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS: mouse speed Apr. 24th, 2007 @ 07:49 AM Reply

oh wow thats awesome.. Thanks!!!

AIDSMcGuff
AIDSMcGuff
  • Member since: Feb. 26, 2006
  • Offline.
Forum Stats
Member
Level 33
Game Developer
Response to AS: mouse speed Apr. 24th, 2007 @ 03:16 PM Reply

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
EvanHayes
EvanHayes
  • Member since: Jan. 13, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: mouse speed Apr. 24th, 2007 @ 03:30 PM Reply

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.

Ertyguy
Ertyguy
  • Member since: Feb. 2, 2006
  • Offline.
Forum Stats
Member
Level 25
Blank Slate
Response to AS: mouse speed Apr. 24th, 2007 @ 04:58 PM Reply

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

trig1
trig1
  • Member since: Oct. 4, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: mouse speed Apr. 24th, 2007 @ 05:11 PM Reply

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.

EvanHayes
EvanHayes
  • Member since: Jan. 13, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: mouse speed Apr. 25th, 2007 @ 07:15 AM Reply

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.

Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: mouse speed Mar. 28th, 2009 @ 06:38 AM Reply

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
StaliN98
StaliN98
  • Member since: Jul. 27, 2007
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: mouse speed Mar. 28th, 2009 @ 09:16 AM Reply

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

Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: mouse speed Mar. 28th, 2009 @ 11:54 PM Reply

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
DawnOfDusk
DawnOfDusk
  • Member since: Feb. 22, 2008
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS: mouse speed Mar. 29th, 2009 @ 02:33 AM Reply

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?

Hoeloe
Hoeloe
  • Member since: Apr. 29, 2004
  • Offline.
Forum Stats
Member
Level 37
Game Developer
Response to AS: mouse speed Mar. 29th, 2009 @ 04:55 AM Reply

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.


Song of the Firefly is on Steam Greenlight and Facebook. Give them a look and support the project!
------------------------------

BBS Signature
ovi1
ovi1
  • Member since: Apr. 22, 2007
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS: mouse speed Mar. 29th, 2009 @ 05:35 AM Reply

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