Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jiquan_pintu
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
wildfirecode13
jiquan_pintu
Commits
1361abf6
Commit
1361abf6
authored
Nov 04, 2021
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
c3ca18c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
9 deletions
+16
-9
drag.ts
src/drag.ts
+16
-9
No files found.
src/drag.ts
View file @
1361abf6
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
;
pic
tureA
.
x
=
picOriginPos
.
x
+
mouseOffsetX
;
pic
tureA
.
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
);
pic
tureA
.
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
:
pic
tureA
.
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
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment