光标移动太快,代码无法阅读
Cursor movement too fast for code to read
我创建了一个 MOUSE_MOVE MouseEvent 和一个在我移动鼠标光标时绘制圆圈的代码。问题是,如果我移动鼠标太快,它不会画出每个圆圈。
这是我为 MOUSE_MOVE 活动准备的代码。
stage.addEventListener(MouseEvent.MOUSE_MOVE, mCursor);
public function mCursor(e:MouseEvent):void
{
var cursor:Shape = new Shape();
cursor.graphics.beginFill(1, 1);
cursor.graphics.drawCircle(e.stageX, e.stageY, 10);
cursor.graphics.endFill();
addChild(cursor);
}
是否有一个算术方程式或物理公式让它把每个圆相加,这样它就可以画出一条中间没有空格的直线?
就用
cursor.graphics.lineTo(…);
在点之间画一条连续的线,而不是添加离散的单个圆圈。
I erased the above codes and just added this one line of code cursor.graphics.lineTo(e.localX, e.localY);
I tested it and there were blanks in between
您必须首先通过调用graphics
对象的lineStyle()
方法来设置线宽。否则线宽为零(默认值)。
这是一份完整的工作文档class:
package
{
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.MouseEvent;
public class Main extends Sprite
{
private var cursor:Shape;
public function Main()
{
cursor = new Shape();
cursor.graphics.lineStyle(2);
addChild(cursor);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mCursor);
}
private function mCursor(e:MouseEvent):void
{
cursor.graphics.lineTo(e.stageX, e.stageY);
}
}
}
您可能需要 fiddle 和 moveTo
来回设置合适的起始位置。正如现在的代码一样,它从 0/0
.
开始
我创建了一个 MOUSE_MOVE MouseEvent 和一个在我移动鼠标光标时绘制圆圈的代码。问题是,如果我移动鼠标太快,它不会画出每个圆圈。
这是我为 MOUSE_MOVE 活动准备的代码。
stage.addEventListener(MouseEvent.MOUSE_MOVE, mCursor);
public function mCursor(e:MouseEvent):void
{
var cursor:Shape = new Shape();
cursor.graphics.beginFill(1, 1);
cursor.graphics.drawCircle(e.stageX, e.stageY, 10);
cursor.graphics.endFill();
addChild(cursor);
}
是否有一个算术方程式或物理公式让它把每个圆相加,这样它就可以画出一条中间没有空格的直线?
就用
cursor.graphics.lineTo(…);
在点之间画一条连续的线,而不是添加离散的单个圆圈。
I erased the above codes and just added this one line of code
cursor.graphics.lineTo(e.localX, e.localY);
I tested it and there were blanks in between
您必须首先通过调用graphics
对象的lineStyle()
方法来设置线宽。否则线宽为零(默认值)。
这是一份完整的工作文档class:
package
{
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.MouseEvent;
public class Main extends Sprite
{
private var cursor:Shape;
public function Main()
{
cursor = new Shape();
cursor.graphics.lineStyle(2);
addChild(cursor);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mCursor);
}
private function mCursor(e:MouseEvent):void
{
cursor.graphics.lineTo(e.stageX, e.stageY);
}
}
}
您可能需要 fiddle 和 moveTo
来回设置合适的起始位置。正如现在的代码一样,它从 0/0
.