Commit 1361abf6 authored by wildfirecode13's avatar wildfirecode13

init

parent c3ca18c8
export const addDragDemo = (stage:FYGE.Stage) => {
const pic = FYGE.Sprite.fromUrl('//yun.duiba.com.cn/aurora/assets/b64757cc9839c1dcc80692f6b7db9d97d269c315.png');
stage.addChild(pic);
export const addDragDemo = (stage: FYGE.Stage) => {
const PIC_SIZE = 200;//图片尺寸,单位像素s
const GAP = 2;//位置间隔
const pictureA = FYGE.Sprite.fromUrl('//yun.duiba.com.cn/aurora/assets/cd16134f2544202ed5676adbd5114286aec44347.png');
stage.addChild(pictureA);
const pictureB = FYGE.Sprite.fromUrl('//yun.duiba.com.cn/aurora/assets/c55dcd277542a6c3e983278ae5835d89848b9bd9.png');
stage.addChild(pictureB);
pictureB.position.set(PIC_SIZE + GAP, 0)
//鼠标按下起始点
let startPoint;
......@@ -8,15 +15,14 @@ export const addDragDemo = (stage:FYGE.Stage) => {
let picOriginPos;
const onStageMove = (event: FYGE.MouseEvent) => {
console.log('触发了onStageMove事件,当前时间戳=>', Date.now())
//鼠标当前位置
const currentPoint = { x: event.stageX, y: event.stageY };
//鼠标按下点到鼠标当前点的偏移量
let mouseOffsetX = currentPoint.x - startPoint.x;
let mouseOffsetY = currentPoint.y - startPoint.y;
pic.x = picOriginPos.x + mouseOffsetX;
pic.y = picOriginPos.y + mouseOffsetY;
pictureA.x = picOriginPos.x + mouseOffsetX;
pictureA.y = picOriginPos.y + mouseOffsetY;
}
const onMouseUp_pic = () => {
......@@ -26,7 +32,7 @@ export const addDragDemo = (stage:FYGE.Stage) => {
const onMouseDown_pic = (event: FYGE.MouseEvent) => {
//图片鼠标弹起事件,事件触发一次即移除,否则会重复添加鼠标弹起事件
pic.once(FYGE.MouseEvent.MOUSE_UP, onMouseUp_pic, this);
pictureA.once(FYGE.MouseEvent.MOUSE_UP, onMouseUp_pic, this);
//添加舞台移动事件,鼠标移动即触发
//FYGE.MouseEvent.MOUSE_MOVE 会在鼠标移动过程中触发
......@@ -36,9 +42,10 @@ export const addDragDemo = (stage:FYGE.Stage) => {
//event.stageX,event.stageY当前鼠标在舞台的位置
startPoint = { x: event.stageX, y: event.stageY };
picOriginPos = { x: pic.x, y: pic.y };
picOriginPos = { x: pictureA.x, y: pictureA.y };
}
//增加鼠标按下事件
pic.addEventListener(FYGE.MouseEvent.MOUSE_DOWN, onMouseDown_pic, this);
pictureA.addEventListener(FYGE.MouseEvent.MOUSE_DOWN, onMouseDown_pic, this);
pictureB.addEventListener(FYGE.MouseEvent.MOUSE_DOWN, onMouseDown_pic, this);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment