应用思考-教育技术论坛
标题:
如何实现拖动图形时实现旋转功能
[打印本页]
作者:
馒头
时间:
2012-4-21 15:21
标题:
如何实现拖动图形时实现旋转功能
我想做一个七巧板拼图的课件,拖拽部分会做,不会让拖拽的图形旋转,想请教高手指点迷津!
作者:
etthink
时间:
2012-4-22 10:45
附群中朋友提供的解决方法:
(, 下载次数: 85)
上传
点击文件名下载附件
var p:Number = Math.PI / 180;
var dx:Number;
var dy:Number;
var angle:Number;
var spr:Sprite=addChild(new Sprite())as Sprite;
spr.x = 275;
spr.y = 200;
var rect_mc:MovieClip=spr.addChild(new MovieClip())as MovieClip;
var circle_mc:MovieClip=spr.addChild(new MovieClip())as MovieClip;
rect_mc.graphics.beginFill (0xff00ff,1);
rect_mc.graphics.drawRect (-100,-50,200,100);
rect_mc.graphics.endFill ();
circle_mc.graphics.beginFill (0x000000,1);
circle_mc.graphics.drawCircle (0,0,6);
circle_mc.graphics.endFill ();
circle_mc.alpha = 0;
rect_mc.addEventListener (MouseEvent.MOUSE_OVER,overHandler);
rect_mc.addEventListener (MouseEvent.MOUSE_OUT,outHandler);
rect_mc.addEventListener (MouseEvent.MOUSE_DOWN,downHandler);
function overHandler (e)
{
circle_mc.alpha = 1;
}
function outHandler (e)
{
circle_mc.alpha = 0;
}
function downHandler (e)
{
spr.startDrag ();
stage.addEventListener (MouseEvent.MOUSE_UP,upHandler);
}
function upHandler (e)
{
spr.stopDrag ();
spr.removeEventListener (MouseEvent.MOUSE_MOVE,sprMove);
}
circle_mc.addEventListener (MouseEvent.MOUSE_OVER,circleOver);
function circleOver (e)
{
circle_mc.alpha = 1;
circle_mc.addEventListener (MouseEvent.MOUSE_DOWN,sprDown);
}
function sprDown (e)
{
spr.addEventListener (MouseEvent.MOUSE_MOVE,sprMove);
stage.addEventListener (MouseEvent.MOUSE_UP,upHandler);
}
function sprMove (e)
{
dx = mouseX - spr.x;
dy = mouseY - spr.y;
angle = Math.atan2(dy,dx) / p;
spr.rotation = angle;
}
复制代码
欢迎光临 应用思考-教育技术论坛 (http://etthink.com/)
Powered by Discuz! X3.4