Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MRBR04
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
template admin
MRBR04
Commits
9b7bade4
Commit
9b7bade4
authored
Apr 28, 2022
by
yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
适配
parent
3ba05101
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
824 additions
and
484 deletions
+824
-484
MRBR04.fire
assets/MRBR04/scene/MRBR04.fire
+600
-483
MRBR04.ts
assets/MRBR04/scene/MRBR04.ts
+1
-1
resizeWidget.ts
assets/MRBR04/scene/resizeWidget.ts
+214
-0
resizeWidget.ts.meta
assets/MRBR04/scene/resizeWidget.ts.meta
+9
-0
No files found.
assets/MRBR04/scene/MRBR04.fire
View file @
9b7bade4
This diff is collapsed.
Click to expand it.
assets/MRBR04/scene/MRBR04.ts
View file @
9b7bade4
...
...
@@ -468,7 +468,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
let
pos1
=
null
;
let
pos2
=
null
;
// if (point1.type == 0) {
pos1
=
lift
.
convertToWorldSpaceAR
(
cc
.
v2
(
lift
.
x
+
lift
.
width
/
2
,
0
));
pos1
=
lift
.
convertToWorldSpaceAR
(
cc
.
v2
(
lift
.
x
+
lift
.
width
/
2
-
10
,
0
));
pos2
=
right
.
convertToWorldSpaceAR
(
cc
.
v2
(
right
.
x
-
right
.
width
/
2
,
0
));
// } else {
// pos1 = this.upOps.node.children[point2.lineIndex].convertToWorldSpaceAR(cc.v2(0, -85));
...
...
assets/MRBR04/scene/resizeWidget.ts
0 → 100644
View file @
9b7bade4
class
CalculativeResize
{
static
resizeInfo
()
{
//0.设计尺寸
let
baseSize
=
cc
.
size
(
2280
,
1242
);
//1.获取屏幕尺寸
let
canvasSize
=
cc
.
view
.
getCanvasSize
();
//2.将屏幕宽高 以高度对齐的方式 换算出场景 宽度
let
sumSizeW
=
cc
.
size
(
canvasSize
.
width
*
baseSize
.
height
/
canvasSize
.
height
,
baseSize
.
height
)
//3.计算场景宽度与设计宽度比率
let
scaleX
=
sumSizeW
.
width
/
baseSize
.
width
;
//高屏幕适配
if
(
scaleX
<=
1
)
{
let
sumSizeY
=
cc
.
size
(
baseSize
.
width
,
canvasSize
.
height
*
(
baseSize
.
width
/
canvasSize
.
width
))
let
scaleY
=
sumSizeY
.
height
/
baseSize
.
height
;
let
posY
=
sumSizeY
.
height
-
baseSize
.
height
;
return
{
scaleX
:
1
,
posX
:
0
,
moveX
:
0
,
scaleY
:
scaleY
,
posY
:
posY
,
moveY
:
-
posY
/
2
}
}
else
{
let
posX
=
sumSizeW
.
width
-
baseSize
.
width
;
//需要拓展的宽度缩放比
return
{
scaleX
:
scaleX
,
posX
:
posX
,
moveX
:
-
posX
/
2
,
scaleY
:
1
,
posY
:
0
,
moveY
:
0
};
}
}
}
//关于齐刘海的适配方案。
//1.需要获取对应的手机型号
//2.需要写上安全间距标记(主要是中间部分)
//3.不同的手机安全间距可能不同。(主要适配iPhone X)
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
@
ccclass
export
default
class
NewClass
extends
cc
.
Component
{
@
property
r_width
=
1
;
@
property
r_height
=
1
;
@
property
r_top
=
0
@
property
r_bottom
=
0
@
property
p_left
=
0
@
property
p_right
=
0
@
property
p_top
=
0
@
property
p_bottom
=
0
@
property
black
=
0
@
property
noHead
=
0
@
property
debug
=
0
@
property
hideHeight
=
0
@
property
hideWidth
=
0
private
resizeScaleX
;
private
resizeScaleY
;
private
posX
;
private
posY
;
private
nodeWidth
;
private
nodeHeight
;
private
nodeX
;
private
nodeY
;
// LIFE-CYCLE CALLBACKS:
onLoad
()
{
let
{
scaleX
,
posX
,
scaleY
,
posY
}
=
CalculativeResize
.
resizeInfo
();
this
.
resizeScaleX
=
scaleX
;
this
.
resizeScaleY
=
scaleY
;
this
.
posX
=
posX
;
this
.
posY
=
posY
;
let
{
width
,
height
,
x
,
y
}
=
this
.
node
;
this
.
nodeWidth
=
width
;
this
.
nodeHeight
=
height
;
this
.
nodeX
=
x
;
this
.
nodeY
=
y
;
//增加一个resize的监听,当屏幕出现宽高比变化的时候,进行一次重新适配。
//主要用于刘海屏的重置,以及动态屏幕变化的控制(虚拟按键屏)。
}
start
()
{
this
.
resize
();
}
update
(
dt
)
{
}
onDestroy
()
{
// if (this.black1)
// pg.view.removChildren(this.black1);
// if (this.black2)
// pg.view.removChildren(this.black2);
// this.black1 = null;
// this.black2 = null;
}
resize
()
{
if
(
!
this
.
resizeScaleX
&&
!
this
.
nodeWidth
)
{
console
.
warn
(
"
手动调用此方法时,不能再onLoad中使用
"
);
return
;
}
this
.
resizeHeight
();
this
.
resizeWidth
();
}
//高屏幕适配
resizeHeight
()
{
if
(
this
.
resizeScaleY
<=
1
)
return
;
let
scaleY
=
this
.
resizeScaleY
;
let
posY
=
this
.
posY
;
let
nodeWidth
=
this
.
nodeWidth
;
let
nodeHeight
=
this
.
nodeHeight
;
let
nodeX
=
this
.
nodeX
;
let
nodeY
=
this
.
nodeY
;
if
(
this
.
debug
==
1
)
{
console
.
log
(
"
断点调试点
"
);
}
if
(
this
.
hideHeight
)
{
this
.
node
.
active
=
false
;
}
//宽度拉伸
if
(
this
.
r_width
==
1
)
{
this
.
node
.
width
=
nodeWidth
*
scaleY
*
1.1
;
}
//高度拉升
if
(
this
.
r_height
==
1
)
{
this
.
node
.
height
=
nodeHeight
*
scaleY
*
1.1
;
}
//动态上移
if
(
this
.
p_top
==
1
)
{
this
.
node
.
y
=
nodeY
+
posY
/
2
}
//动态下移
if
(
this
.
p_bottom
==
1
)
{
this
.
node
.
y
=
nodeY
-
posY
/
2
}
}
//长屏幕适配
resizeWidth
()
{
if
(
this
.
resizeScaleX
<=
1
)
return
;
let
resizeScaleX
=
this
.
resizeScaleX
;
let
posX
=
this
.
posX
;
let
nodeWidth
=
this
.
nodeWidth
;
let
nodeHeight
=
this
.
nodeHeight
;
let
nodeX
=
this
.
nodeX
;
let
nodeY
=
this
.
nodeY
;
if
(
this
.
debug
==
1
)
{
console
.
log
(
"
断点调试点
"
);
}
if
(
this
.
hideWidth
)
{
this
.
node
.
active
=
false
;
}
//宽度拉伸
if
(
this
.
r_width
==
1
)
{
this
.
node
.
width
=
nodeWidth
*
resizeScaleX
*
1.1
;
}
//高度拉升
if
(
this
.
r_height
==
1
)
{
this
.
node
.
height
=
nodeHeight
*
resizeScaleX
*
1.1
;
//高度拉伸后,图片顶部齐边【坐标下移】 y坐标下移
if
(
this
.
r_top
==
1
)
{
this
.
node
.
y
=
nodeY
-
nodeHeight
*
(
resizeScaleX
-
1
)
/
2
;
}
//高度拉伸后,图片底部齐边【坐标上移】 y坐标上移
if
(
this
.
r_bottom
==
1
)
{
this
.
node
.
y
=
nodeY
+
nodeHeight
*
(
resizeScaleX
-
1
)
/
2
;
}
}
//如果是刘海屏,减去对应的刘海屏的宽度
let
lhpSize
=
{
top
:
0
,
bottom
:
0
};
if
(
!
this
.
noHead
&&
posX
!=
0
)
lhpSize
=
{
top
:
44
*
1.5
,
bottom
:
34
*
1.5
};
//动态左移
if
(
this
.
p_left
==
1
)
{
this
.
node
.
x
=
nodeX
-
posX
/
2
+
lhpSize
.
top
;
}
//动态右移
if
(
this
.
p_right
==
1
)
{
this
.
node
.
x
=
nodeX
+
posX
/
2
-
lhpSize
.
bottom
;
}
}
//屏幕适配--end
createBalck
()
{
let
black
=
cc
.
instantiate
(
cc
.
find
(
'
Canvas/blackBg
'
));
return
black
;
}
setBlackActive
(
val
)
{
// if (this.black1)
// this.black1.active = val;
// if (this.black2)
// this.black2.active = val;
}
}
\ No newline at end of file
assets/MRBR04/scene/resizeWidget.ts.meta
0 → 100644
View file @
9b7bade4
{
"ver": "1.0.8",
"uuid": "41ab1343-86ca-4a9c-aef5-b556b5dad99b",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
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