Files
CocosCreator-Multi-resoluti…/assets/Script/MultiResolution/CloseToBorderComponent.ts

29 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import MultiResolutionCompat from "./MultiResoultionCompat";
const { ccclass, property } = cc._decorator;
@ccclass
export default class CloseToBorderComponent extends cc.Component {
@property()
isCloseToBottom: boolean = false;
@property()
closeToBottonPx: number = 0;
onLoad() {
this.node.position = this.getShowAllModeNodePositionCloseToBottom(this.node.position);
}
/**
* 计算当前游戏设计分辨率在ShowAll模式适配后传入来的原始坐标在ShowAll模式下的「贴近屏幕底部」实际坐标值
*/
getShowAllModeNodePositionCloseToBottom(nodePosInDesign: cc.Vec2): cc.Vec2 {
let srcScaleForShowAll = MultiResolutionCompat.getShowAllModeScale();
let bottomBorderHeightInCanvas = MultiResolutionCompat.getShowAllModeVerticalBorderHeight() / 2;
let srcNodePosYInCanvas = nodePosInDesign.y * srcScaleForShowAll;
let finalNodePosYInCanvas = srcNodePosYInCanvas - bottomBorderHeightInCanvas;
let nodePosYInDesign = finalNodePosYInCanvas / srcScaleForShowAll;
return cc.v2(nodePosInDesign.x, nodePosYInDesign);
}
}