问题描述
我创建在AS3它加载PNG图像所需的块,使它们在一个容器基于栅格地图渲染器。我申请滚动/拖入逻辑使用MOUSE_MOVE事件处理这个程序。我要做的就是,
I am creating grid based map renderer in AS3 which loads required chunks of PNG images and render them in a container. I've applied scrolling/dragging logic in this app using MOUSE_MOVE event handler. What I do is,
我注册bDragging旗MOUSE_DOWN和鼠标位置,在每一个MOUSE_MOVE,我检查了鼠标位移和移动主地图相应取消注册bDragging标志MOUSE_UP以及设置位置为NaN。
I register bDragging flag in MOUSE_DOWN and position of mouse,In every MOUSE_MOVE, I check displacement of mouse and move main map accordinglyUnregister bDragging flag in MOUSE_UP and set position to NaN.
我的问题是拖颇为生涩/不稳了。
My problem is dragging is quite jerky/shaky.
任何建议将AP preciated。下面是示例code我使用。
Any suggestion would be appreciated. following is sample code I'm using.
function onMouseDown(e:MouseEvent):void
{
m_bDragging = true;
m_ptPrevPoint = new Point(e.stageX, e.stageY);
}
function onMouseUp(e:MouseEvent):void
{
m_bDragging = false;
m_ptPrevPoint = null;
}
function onMouseMove(e:MouseEvent):void
{
if(!m_bDragging || null == m_ptPrevPoint)
return;
var nDiffX:Number = int(e.stageX - m_ptPrevPoint.x);
var nDiffY:Number = int(e.stageY - m_ptPrevPoint.y);
//Make movement smoother
//nDiffX = nDiffX * 4) / 4;
//nDiffY = nDiffY * 4) / 4;
if(nDiffX != 0 || nDiffY != 0)
{
trace("X : " + nDiffX + ", Y : " + nDiffY + ", points-Old " + m_ptPrevPoint + ", New " + new Point(e.stageX, e.stageY) );
m_oCircle.x += nDiffX;
m_oCircle.y += nDiffY;
m_ptPrevPoint = new Point(e.stageX, e.stageY);
e.updateAfterEvent();
}
else
trace("not moved - X : " + nDiffX + ", Y : " + nDiffY+ ", points-Old " + m_ptPrevPoint + ", New " + new Point(e.stageX, e.stageY)) }
请检查FLA文件在这里......在Flash CS3中进行。请注意,如果鼠标是圆上,将挺举像地狱,但如果你从圈外拖动它,它会更加顺利!
Please check FLA file here...made in Flash CS3. Please note if mouse is on circle it will jerk like hell but if you drag it from outside of circle, It will go smoother!
推荐答案
谢谢你们,我想通了这个问题!
Thanks guys, I figured out the problem!
其实,这可能是土坯的一些bug,我奇怪地得到一些奇怪的坐标,这就是原因运动并不顺利。我转换stageX和不自然的使用localToGlobal,一切都变得更顺畅!
actually this might be some bug of adobe, I was strangely getting some odd coordinates and that was the reason movement was not smooth. I converted stageX and stageY using localToGlobal and everything became smoother!!!
现在,我不知道我为什么要需要stageX /不自然的转化为全球性的。 :)我简短的变化如下图所示。
now, I dont know why should I be needed to convert stageX/stageY to global. :) my brief changes are as below.
VAR curPt:点=的DisplayObject(e.currentTarget).localToGlobal(新点(e.stageX,e.stageY));
var curPt:Point = DisplayObject(e.currentTarget).localToGlobal(new Point(e.stageX, e.stageY));
VAR nDiffX:数= INT(curPt.x - m_pt prevPoint.x);
var nDiffX:Number = int(curPt.x - m_ptPrevPoint.x);
VAR nDiffY:数= INT(curPt.y - m_pt prevPoint.y);
var nDiffY:Number = int(curPt.y - m_ptPrevPoint.y);
谢谢你们,每一个帮助AP preciated。
Thanks guys, every help appreciated.
这篇关于使用MOUSE_MOVE事件的Flash AS3 custome拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!