Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fyge_for_tb
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王剑峰
fyge_for_tb
Commits
b74d8660
Commit
b74d8660
authored
Jun 24, 2022
by
邱旭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
合并2.0.70一点东西
parent
36e2ca2a
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
814 additions
and
28 deletions
+814
-28
FpsPanel.ts
src/2d/FpsPanel.ts
+102
-0
Container.ts
src/2d/display/Container.ts
+37
-8
Event.ts
src/2d/events/Event.ts
+12
-18
ScrollView.ts
src/2d/ui/ScrollView.ts
+661
-0
index.ts
src/index.ts
+2
-2
No files found.
src/2d/FpsPanel.ts
0 → 100644
View file @
b74d8660
import
{
createCanvas
}
from
"./utils"
;
import
{
Sprite
}
from
"./display"
;
import
{
Texture
}
from
"./texture"
;
export
class
FpsPanel
extends
Sprite
{
private
context
:
CanvasRenderingContext2D
;
private
bgColor
:
string
=
'#002002'
;
private
textColor
:
string
=
'#0ff0ff'
;
private
PR
:
number
=
3
;
private
WIDTH
=
80
*
this
.
PR
;
private
HEIGHT
=
48
*
this
.
PR
;
private
TEXT_X
=
3
*
this
.
PR
;
private
TEXT_Y
=
2
*
this
.
PR
;
private
GRAPH_X
=
3
*
this
.
PR
;
private
GRAPH_Y
=
15
*
this
.
PR
;
private
GRAPH_WIDTH
=
74
*
this
.
PR
;
private
GRAPH_HEIGHT
=
30
*
this
.
PR
;
private
GRAPH_SIZE
=
74
;
private
maxValue
=
120
;
private
min
=
Infinity
;
private
max
=
0
;
private
items
=
[];
/**
* 帧率面板
* 后续可以加入每次drawCall,总绘制对象等等
*/
constructor
()
{
super
()
//离屏canvas
var
canvas
=
createCanvas
();
canvas
.
width
=
this
.
WIDTH
;
canvas
.
height
=
this
.
HEIGHT
;
this
.
texture
=
Texture
.
fromCanvas
(
canvas
)
this
.
context
=
canvas
.
getContext
(
"2d"
);
this
.
context
.
font
=
'bold '
+
(
9
*
this
.
PR
)
+
'px Helvetica,Arial,sans-serif'
;
this
.
context
.
textBaseline
=
'top'
;
this
.
updateText
(
"FPS"
);
}
private
lastTime
:
number
=
Date
.
now
();
private
frames
:
number
=
0
;
reset
()
{
this
.
lastTime
=
Date
.
now
();
this
.
min
=
Infinity
;
this
.
max
=
0
;
this
.
items
.
length
=
0
;
this
.
frames
=
0
;
}
update
()
{
this
.
frames
++
;
var
time
=
Date
.
now
();
//每秒跑一次
if
(
time
>=
this
.
lastTime
+
1000
)
{
var
value
=
(
this
.
frames
*
1000
)
/
(
time
-
this
.
lastTime
);
this
.
updatePanel
(
value
)
this
.
lastTime
=
time
;
this
.
frames
=
0
;
}
super
.
update
();
}
private
updatePanel
(
value
:
number
)
{
const
{
items
,
GRAPH_SIZE
,
context
,
GRAPH_X
,
textColor
,
GRAPH_Y
,
PR
,
GRAPH_HEIGHT
,
bgColor
,
maxValue
}
=
this
items
.
push
(
value
);
while
(
items
.
length
>
GRAPH_SIZE
)
{
items
.
shift
();
}
this
.
min
=
Math
.
min
(
this
.
min
,
value
);
this
.
max
=
Math
.
max
(
this
.
max
,
value
);
this
.
updateText
(
Math
.
round
(
value
)
+
' FPS ('
+
Math
.
round
(
this
.
min
)
+
'-'
+
Math
.
round
(
this
.
max
)
+
')'
);
for
(
var
i
=
0
;
i
<
items
.
length
;
i
++
)
{
var
startPos
=
GRAPH_X
+
(
i
+
GRAPH_SIZE
-
items
.
length
)
*
PR
;
context
.
fillStyle
=
textColor
;
context
.
globalAlpha
=
1
;
context
.
fillRect
(
startPos
,
GRAPH_Y
,
PR
,
GRAPH_HEIGHT
);
context
.
fillStyle
=
bgColor
;
context
.
globalAlpha
=
0.9
;
context
.
fillRect
(
startPos
,
GRAPH_Y
,
PR
,
Math
.
round
((
1
-
(
items
[
i
]
/
maxValue
))
*
GRAPH_HEIGHT
));
}
this
.
texture
.
update
();
}
private
updateText
(
text
:
string
)
{
const
{
context
,
bgColor
,
textColor
,
WIDTH
,
HEIGHT
,
TEXT_X
,
TEXT_Y
,
GRAPH_X
,
GRAPH_Y
,
GRAPH_WIDTH
,
GRAPH_HEIGHT
}
=
this
context
.
fillStyle
=
bgColor
;
context
.
globalAlpha
=
1
;
context
.
fillRect
(
0
,
0
,
WIDTH
,
HEIGHT
);
context
.
fillStyle
=
textColor
;
context
.
fillText
(
text
,
TEXT_X
,
TEXT_Y
);
context
.
fillRect
(
GRAPH_X
,
GRAPH_Y
,
GRAPH_WIDTH
,
GRAPH_HEIGHT
);
context
.
fillStyle
=
bgColor
;
context
.
globalAlpha
=
0.9
;
context
.
fillRect
(
GRAPH_X
,
GRAPH_Y
,
GRAPH_WIDTH
,
GRAPH_HEIGHT
);
}
}
src/2d/display/Container.ts
View file @
b74d8660
...
...
@@ -55,7 +55,7 @@ export default class Container extends DisplayObject {
}
/**
* 批量添加child
* @param children
* @param children
*/
addChildren
<
T
extends
DisplayObject
>
(...
children
:
T
[]):
T
[]
{
children
.
forEach
((
child
:
T
)
=>
{
this
.
addChild
(
child
);
})
...
...
@@ -167,7 +167,7 @@ export default class Container extends DisplayObject {
/**
* 设置child的层级索引
* @param {DisplayObject} child
* @param {DisplayObject} child
* @param {number} index
*/
setChildIndex
(
child
:
DisplayObject
,
index
:
number
)
{
...
...
@@ -176,7 +176,7 @@ export default class Container extends DisplayObject {
/**
* 根据索引获取子级对象
* @param {number} index
* @param {number} index
* @return {DisplayObject}
*/
getChildAt
(
index
:
number
):
DisplayObject
{
...
...
@@ -188,9 +188,9 @@ export default class Container extends DisplayObject {
/**
* 通过名字获取子级
* @param name
* @param isOnlyOne
* @param isRecursive
* @param name
* @param isOnlyOne
* @param isRecursive
*/
public
getChildByName
(
name
:
string
|
RegExp
,
isOnlyOne
:
boolean
=
true
,
isRecursive
:
boolean
=
false
):
any
{
if
(
!
name
)
return
null
;
...
...
@@ -216,7 +216,7 @@ export default class Container extends DisplayObject {
/**
* 移除child
* @param {DisplayObject} child
* @return {DisplayObject}
* @return {DisplayObject}
*/
removeChild
(
child
:
DisplayObject
):
DisplayObject
{
...
...
@@ -231,7 +231,7 @@ export default class Container extends DisplayObject {
/**
* 在index索引处移除子级对象
* @param {number} index
* @param {number} index
* @return {DisplayObject} 移除的子级对象
*/
removeChildAt
(
index
:
number
):
DisplayObject
{
...
...
@@ -671,6 +671,35 @@ export default class Container extends DisplayObject {
}
}
}
/**
* 操作子级的所有方法,需要维护
*/
public
static
_childrenOperationMethods
:
string
[]
=
[
//添加子级的方法
"addChild"
,
"addChildAt"
,
"addChildren"
,
//移除子级的方法
"removeChild"
,
"removeChildAt"
,
"removeChildren"
,
"removeAllChildren"
,
"removeChildrenAt"
,
"spliceChildren"
,
//获取子级的方法
"getChildAt"
,
"getChildByName"
,
"getChildrenByName"
,
//获取子级索引的方法
"getChildIndex"
,
//改变子级索引的方法
"setChildIndex"
,
"swapChildren"
]
}
Container
.
prototype
.
containerUpdateTransform
=
Container
.
prototype
.
updateTransform
;
function
judgeMaskEnable
(
mask
):
boolean
{
if
(
!
mask
)
return
false
;
//Shape遮罩,或者Sprite遮罩
if
(
mask
.
texture
)
{
mask
.
updateShape
&&
mask
.
updateShape
();
//更新一下
if
(
!
mask
.
texture
.
valid
)
return
false
;
}
//Graphics遮罩,其实这个判断也包括了Sprite的纹理为空的情况
else
if
(
!
mask
.
graphicsData
||
!
mask
.
graphicsData
.
length
)
{
return
false
;
}
return
true
;
}
src/2d/events/Event.ts
View file @
b74d8660
...
...
@@ -19,7 +19,7 @@ export class Event extends HashObject {
public
static
RESIZE
:
string
=
"onResize"
;
/**
* Scroll
Page
组件滑动到开始位置事件
* Scroll组件滑动到开始位置事件
* @property SCROLL_TO_HEAD
* @static
* @since 1.1.0
...
...
@@ -27,7 +27,7 @@ export class Event extends HashObject {
*/
public
static
SCROLL_TO_HEAD
:
string
=
"onScrollToHead"
;
/**
* Scroll
Page
组件停止滑动事件
* Scroll组件停止滑动事件
* @property SCROLL_STOP
* @static
* @since 1.1.0
...
...
@@ -35,7 +35,7 @@ export class Event extends HashObject {
*/
public
static
SCROLL_STOP
:
string
=
"onScrollStop"
;
/**
* Scroll
Page
组件开始滑动事件
* Scroll组件开始滑动事件
* @property SCROLL_START
* @static
* @since 1.1.0
...
...
@@ -43,13 +43,17 @@ export class Event extends HashObject {
*/
public
static
SCROLL_START
:
string
=
"onScrollStart"
;
/**
* Scroll
Page
组件滑动到结束位置事件
* @property
ON_
SCROLL_TO_END
* Scroll组件滑动到结束位置事件
* @property SCROLL_TO_END
* @static
* @since 1.1.0
* @type {string}
*/
public
static
SCROLL_TO_END
:
string
=
"onScrollToEnd"
;
/**
* Scroll组件滚动时触发
*/
public
static
SCROLLING
:
string
=
"onScrolling"
;
/**
* 舞台初始化完成后会触发的事件
* @property INIT_STAGE
...
...
@@ -71,7 +75,7 @@ export class Event extends HashObject {
/**
* 显示对象从舞台移出事件
* @Event
* @property REMOVE
_TO
_STAGE
* @property REMOVE
D_FROM
_STAGE
* @type {string}
* @static
* @public
...
...
@@ -89,7 +93,7 @@ export class Event extends HashObject {
*/
public
static
ENTER_FRAME
:
string
=
"onEnterFrame"
;
/**
*
Movie
Clip 播放完成事件
*
Animation
Clip 播放完成事件
* @Event
* @property END_FRAME
* @type {string}
...
...
@@ -98,16 +102,6 @@ export class Event extends HashObject {
* @since 1.0.0
*/
public
static
END_FRAME
:
string
=
"onEndFrame"
;
/**
* MovieClip 帧标签事件
* @Event
* @property CALL_FRAME
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public
static
CALL_FRAME
:
string
=
"onCallFrame"
;
/**
* 完成事件
* @Event
...
...
@@ -234,7 +228,7 @@ export class Event extends HashObject {
}
/**
* 重
围事件到初始状态方便重复利用
* 重
置事件
* @method reset
* @param {string} type
* @param target
...
...
src/2d/ui/ScrollView.ts
0 → 100644
View file @
b74d8660
This diff is collapsed.
Click to expand it.
src/index.ts
View file @
b74d8660
...
...
@@ -35,5 +35,5 @@ export * from "./3d";
//spine
export
*
from
"./spine"
;
// export * from "./Stats";
\ No newline at end of file
//fps面板,后续可以加入每次drawCall,总绘制对象等等
export
*
from
"./2d/FpsPanel"
;
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