This content has been marked as final.
Show 3 replies

1. Re: Volume linked to cursor proximity
Newsgroup_User Jun 29, 2008 7:42 PM (in response to Bob220867)property spriteNum
on exitFrame me
 calculates the distance between the cursor
 and the registration point, using
 Pythagorean theorem:
 a squared plus b squared equals c squared
a = abs(sprite(spriteNum).locH  the mouseH)
b = abs(sprite(spriteNum).locV  the mouseV)
c = sqrt (a * a + b * b)
put c
end 
2. Re: Volume linked to cursor proximity
Newsgroup_User Jun 29, 2008 8:26 PM (in response to Bob220867)> a = abs(sprite(spriteNum).locH  the mouseH)
> b = abs(sprite(spriteNum).locV  the mouseV)
FWIW, there's no need to take the absolute value since when squared the
result will always be positive (ignoring imaginary numbers...)
> c = sqrt (a * a + b * b) 
3. Re: Volume linked to cursor proximity
Newsgroup_User Jun 29, 2008 8:41 PM (in response to Bob220867)Sean Wilson wrote:
>> a = abs(sprite(spriteNum).locH  the mouseH)
>> b = abs(sprite(spriteNum).locV  the mouseV)
>
> FWIW, there's no need to take the absolute value since when squared the
> result will always be positive (ignoring imaginary numbers...)
>
>> c = sqrt (a * a + b * b)
True, good point. Given that this is executing on every exitFrame event,
one less function call could improve performance. So

property spriteNum
on exitFrame me
 calculates the distance between the cursor
 and the registration point, using
 Pythagorean theorem:
 a squared plus b squared equals c squared
a = sprite(spriteNum).locH  the mouseH
b = sprite(spriteNum).locV  the mouseV
c = sqrt (a * a + b * b)
put c
end

Bob, you should be able to replace the "put c" line with your own code
to adjust the volume depending on the value of c.