Actionscript 3 影片剪辑排斥鼠标光标
我正在尝试构建一个应用程序,其中鼠标光标用于“吹动”电影剪辑。我这样做的方法是让鼠标光标排斥动画剪辑。
问题是,我只能让它在影片剪辑的顶部和左侧工作。
这是我的代码:
function moveCloud(event:Event):void {
var yChange:Number = Math.round(mouseY-cloud.y);
var xChange:Number = Math.round(mouseX-cloud.x);
//var yMove:Number = Math.round(yChange);
//var xMove:Number = Math.round(xChange);
var dist:Number = Math.sqrt(xChange*xChange + yChange*yChange);
trace(dist);
if(dist < 100)
{
var angle:Number = Math.atan2(yChange, xChange);
cloud.y += Math.cos(angle)*2;
cloud.x += Math.sin(angle)*2;
}
有人以前做过类似的事情或有任何想法吗?
I'm trying to build an application where the themouse cursor is used to "blow" a movieclip around. The way I'm doing this is by making the mouse cursor repel the movieclip.
The problem is, I can only get it to work on the top and the left of the movieclip.
Here's my code:
function moveCloud(event:Event):void {
var yChange:Number = Math.round(mouseY-cloud.y);
var xChange:Number = Math.round(mouseX-cloud.x);
//var yMove:Number = Math.round(yChange);
//var xMove:Number = Math.round(xChange);
var dist:Number = Math.sqrt(xChange*xChange + yChange*yChange);
trace(dist);
if(dist < 100)
{
var angle:Number = Math.atan2(yChange, xChange);
cloud.y += Math.cos(angle)*2;
cloud.x += Math.sin(angle)*2;
}
Anyone done something like this before or have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需更改正弦和余弦并减去它而不是添加。
Just change sine and cosine and substract it instead of adding.