有没有办法让spriteframe选择的图片尺寸去适应节点高度 | 您所在的位置:网站首页 › 适应我的尺寸 › 有没有办法让spriteframe选择的图片尺寸去适应节点高度 |
@author chenkai 2021.6.24 */ @ccclass export default class ImgFixedSize extends cc.Component { public get fixedSize(){ return this._fixedSize; } @property({type:cc.Integer, tooltip:“固定尺寸”}) public set fixedSize(value){ this._fixedSize = value; this.onSizeChanged(); } /**固定尺寸 */ private _fixedSize:number = 0; onLoad() { this.node.on(cc.Node.EventType.SIZE_CHANGED, this.onSizeChanged, this); this.onSizeChanged(); } /**当尺寸变化时,重置node节点大小 */ onSizeChanged() { var width = this.node.width; var height = this.node.height; var max = Math.max(width, height); this.node.scale = this.fixedSize / max; } } |
CopyRight 2018-2019 实验室设备网 版权所有 |