Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
game-stydy
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
谌继荃
game-stydy
Commits
46fa1ecb
Commit
46fa1ecb
authored
Nov 04, 2021
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
1361abf6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
16 deletions
+21
-16
drag.ts
src/drag.ts
+21
-16
No files found.
src/drag.ts
View file @
46fa1ecb
...
...
@@ -2,50 +2,55 @@ export const addDragDemo = (stage: FYGE.Stage) => {
const
PIC_SIZE
=
200
;
//图片尺寸,单位像素s
const
GAP
=
2
;
//位置间隔
const
picture
A
=
FYGE
.
Sprite
.
fromUrl
(
'//yun.duiba.com.cn/aurora/assets/cd16134f2544202ed5676adbd5114286aec44347.png'
);
stage
.
addChild
(
picture
A
);
const
picture
1
=
FYGE
.
Sprite
.
fromUrl
(
'//yun.duiba.com.cn/aurora/assets/cd16134f2544202ed5676adbd5114286aec44347.png'
);
stage
.
addChild
(
picture
1
);
const
picture
B
=
FYGE
.
Sprite
.
fromUrl
(
'//yun.duiba.com.cn/aurora/assets/c55dcd277542a6c3e983278ae5835d89848b9bd9.png'
);
stage
.
addChild
(
picture
B
);
picture
B
.
position
.
set
(
PIC_SIZE
+
GAP
,
0
)
const
picture
2
=
FYGE
.
Sprite
.
fromUrl
(
'//yun.duiba.com.cn/aurora/assets/c55dcd277542a6c3e983278ae5835d89848b9bd9.png'
);
stage
.
addChild
(
picture
2
);
picture
2
.
position
.
set
(
PIC_SIZE
+
GAP
,
0
)
//鼠标按下起始点
let
startPoint
;
//图片起始位置
let
picOriginPos
;
let
currentPictureOrigin
;
const
onStageMove
=
(
event
:
FYGE
.
MouseEvent
)
=>
{
const
onStageMove
=
(
currentPicture
:
FYGE
.
Sprite
,
event
:
FYGE
.
MouseEvent
)
=>
{
//鼠标当前位置
const
currentPoint
=
{
x
:
event
.
stageX
,
y
:
event
.
stageY
};
//鼠标按下点到鼠标当前点的偏移量
let
mouseOffsetX
=
currentPoint
.
x
-
startPoint
.
x
;
let
mouseOffsetY
=
currentPoint
.
y
-
startPoint
.
y
;
pictureA
.
x
=
picOriginPos
.
x
+
mouseOffsetX
;
pictureA
.
y
=
picOriginPos
.
y
+
mouseOffsetY
;
currentPicture
.
x
=
currentPictureOrigin
.
x
+
mouseOffsetX
;
currentPicture
.
y
=
currentPictureOrigin
.
y
+
mouseOffsetY
;
}
const
onMouseUp_pic
=
()
=>
{
const
onMouseUp_pic
=
(
onStageMoveBinded
:
Function
)
=>
{
//鼠标抬起后应该移出舞台移动事件,否则会重复添加事件
stage
.
removeEventListener
(
FYGE
.
MouseEvent
.
MOUSE_MOVE
,
onStageMove
,
this
);
stage
.
removeEventListener
(
FYGE
.
MouseEvent
.
MOUSE_MOVE
,
onStageMove
Binded
,
this
);
}
const
onMouseDown_pic
=
(
event
:
FYGE
.
MouseEvent
)
=>
{
const
currentPicture
=
event
.
target
;
const
onStageMoveBinded
=
onStageMove
.
bind
(
this
,
currentPicture
);
//图片鼠标弹起事件,事件触发一次即移除,否则会重复添加鼠标弹起事件
pictureA
.
once
(
FYGE
.
MouseEvent
.
MOUSE_UP
,
onMouseUp_pic
,
this
);
currentPicture
.
once
(
FYGE
.
MouseEvent
.
MOUSE_UP
,
onMouseUp_pic
.
bind
(
this
,
onStageMoveBinded
)
,
this
);
//添加舞台移动事件,鼠标移动即触发
//FYGE.MouseEvent.MOUSE_MOVE 会在鼠标移动过程中触发
stage
.
addEventListener
(
FYGE
.
MouseEvent
.
MOUSE_MOVE
,
onStageMove
,
this
);
stage
.
addEventListener
(
FYGE
.
MouseEvent
.
MOUSE_MOVE
,
onStageMove
Binded
,
this
);
//event事件对象
//event.stageX,event.stageY当前鼠标在舞台的位置
startPoint
=
{
x
:
event
.
stageX
,
y
:
event
.
stageY
};
picOriginPos
=
{
x
:
pictureA
.
x
,
y
:
pictureA
.
y
};
currentPictureOrigin
=
{
x
:
currentPicture
.
x
,
y
:
currentPicture
.
y
};
stage
.
addChildAt
(
currentPicture
,
stage
.
children
.
length
-
1
);
}
//增加鼠标按下事件
picture
A
.
addEventListener
(
FYGE
.
MouseEvent
.
MOUSE_DOWN
,
onMouseDown_pic
,
this
);
picture
B
.
addEventListener
(
FYGE
.
MouseEvent
.
MOUSE_DOWN
,
onMouseDown_pic
,
this
);
picture
1
.
addEventListener
(
FYGE
.
MouseEvent
.
MOUSE_DOWN
,
onMouseDown_pic
,
this
);
picture
2
.
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