有没有办法让spriteframe选择的图片尺寸去适应节点高度 您所在的位置:网站首页 适应我的尺寸 有没有办法让spriteframe选择的图片尺寸去适应节点高度

有没有办法让spriteframe选择的图片尺寸去适应节点高度

2024-06-29 02:59| 来源: 网络整理| 查看: 265

@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 实验室设备网 版权所有