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
5ca7642d
Commit
5ca7642d
authored
Mar 10, 2021
by
邱旭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
08.FlppyBird-模拟重力
parent
ffdce49d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
75 deletions
+16
-75
lib.js
lib/lib.js
+16
-75
No files found.
lib/lib.js
View file @
5ca7642d
...
@@ -8,94 +8,36 @@
...
@@ -8,94 +8,36 @@
* 抽象了一个简单的GameObject
* 抽象了一个简单的GameObject
*/
*/
class
GameObject
{
class
GameObject
{
id
;
// 绑定的dom元素的id
id
;
// 绑定的dom元素的id
dom
;
// 绑定的dom元素
dom
;
// 绑定的dom元素
/**
// 位置
* transform 表示显示对象的变换
top
=
0
;
* @type {{rotate: number, scale: {x: number, y: number}, position: {top: number, left: number}}}
left
=
0
;
*/
transform
=
{
position
:
{
top
:
0
,
left
:
0
},
// 位置
scale
:
{
x
:
1
,
y
:
1
},
// 缩放
rotate
:
0
,
// 旋转
}
constructor
(
id
)
{
// 缩放
this
.
id
=
id
;
scaleX
=
1
;
this
.
dom
=
document
.
getElementById
(
id
);
// 在构造函数中绑定dom元素
scaleY
=
1
;
this
.
dom
.
style
.
position
=
"absolute"
;
}
// 旋转
rotate
=
0
;
/**
/**
* 获得宽高
* 获得宽高
* @returns {{width: number, height: number}}
* @returns {{width: number, height: number}}
*/
*/
get
S
ize
()
{
get
s
ize
()
{
return
{
return
{
width
:
this
.
dom
.
clientWidth
,
width
:
this
.
dom
.
clientWidth
,
height
:
this
.
dom
.
clientHeight
,
height
:
this
.
dom
.
clientHeight
,
}
}
}
}
constructor
(
id
)
{
/**
this
.
id
=
id
;
* 设置Position
this
.
dom
=
document
.
getElementById
(
id
);
// 在构造函数中绑定dom元素
* @param top
this
.
dom
.
style
.
position
=
"absolute"
;
* @param left
*/
setPosition
(
top
=
this
.
transform
.
position
.
top
,
left
=
this
.
transform
.
position
.
left
)
{
this
.
transform
.
position
.
top
=
top
;
this
.
transform
.
position
.
left
=
left
;
}
/**
* 设置Scale
* @param x
* @param y
*/
setScale
(
x
=
this
.
transform
.
scale
.
x
,
y
=
this
.
transform
.
scale
.
y
)
{
this
.
transform
.
scale
.
x
=
x
;
this
.
transform
.
scale
.
y
=
y
;
}
/**
* 设置Rotate
* @param rotate
*/
setRotate
(
rotate
=
this
.
transform
.
rotate
)
{
this
.
transform
.
rotate
=
rotate
;
}
/**
* 获得Position
* @returns {{top: number, left: number}}
*/
getPosition
()
{
return
{
top
:
this
.
transform
.
position
.
top
,
left
:
this
.
transform
.
position
.
left
,
}
}
/**
* 获得Scale
* @returns {{x: number, y: number}}
*/
getScale
()
{
return
{
x
:
this
.
transform
.
scale
.
x
,
y
:
this
.
transform
.
scale
.
y
,
}
}
/**
* 获得Rotate
* @returns {number}
*/
getRotate
()
{
return
this
.
transform
.
rotate
;
}
}
/**
/**
...
@@ -109,9 +51,7 @@ class GameObject {
...
@@ -109,9 +51,7 @@ class GameObject {
* 抽离渲染部分
* 抽离渲染部分
*/
*/
render
()
{
render
()
{
const
{
top
,
left
}
=
this
.
getPosition
();
const
{
top
,
left
,
scaleX
,
scaleY
,
rotate
}
=
this
;
const
{
x
:
scaleX
,
y
:
scaleY
}
=
this
.
getScale
();
const
rotate
=
this
.
getRotate
();
this
.
dom
.
style
.
top
=
top
+
"px"
;
this
.
dom
.
style
.
top
=
top
+
"px"
;
this
.
dom
.
style
.
left
=
left
+
"px"
;
this
.
dom
.
style
.
left
=
left
+
"px"
;
...
@@ -124,4 +64,5 @@ class GameObject {
...
@@ -124,4 +64,5 @@ class GameObject {
destroy
()
{
destroy
()
{
}
}
}
}
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