typescipt在一定范围内加载图片按照等比排列

 加载10张图片 排列显示 间距50像素  差不多跟这个图片一样
第二部 添加Resize的侦听,舞台宽高变化的时候调整排列
第三部 把所有加载的图片等比缩放显示在100*100的范围内排列显示,具体代码如何实现,求解答
Has invited:

umi

Favor from:

 


TIM图片20180310113142_-_副本.png


 
myTestUI.imgList.spaceX = myTestUI.imgList.spaceY = 50;
    myTestUI.imgList.array = ['comp/bg.png', 'comp/btn_close.png', 'comp/button.png', 'comp/image.png'];
    myTestUI.imgList.renderHandler = new Laya.Handler(this, onImgListRender);
 
function onImgListRender(box: Laya.Box) {
    let model = box.dataSource;
    let panel = box.getChildByName('panel') as Laya.Panel;
    let img = panel.getChildByName('img') as Laya.Image; 
    img.skin = model;
    let reset = function () {
        let source = img.source;
        if (source) {
//Math.max是左边的效果,min是右边的效果
            let ratio = Math.max(source.width, source.height) / 100;
            img.width = source.width / ratio;
            img.height = source.height / ratio;
        }
    }
    reset();
    img.on(Laya.Event.LOADED, this, () => {
        reset();
    });
}

要回复问题请先登录注册