Creator适配屏幕

2021-06-09  本文已影响0人  Albert_d37d

const {ccclass, property} = cc._decorator;

@ccclass

export default class NewClass extends cc.Component {

    onLoad()

    {

        let ratio = cc.winSize.height / cc.winSize.width;

        ratio = parseInt(ratio.toFixed(1));

      //  console.log("mylog  ratio = " + ratio);

        if(ratio <= 1.3)

        {

      //      console.log("mylog match height");

            this.node.getComponent(cc.Canvas).fitHeight = true;

            this.node.getComponent(cc.Canvas).fitWidth = false;

        }else

        {

      //    console.log("mylog match width");

            this.node.getComponent(cc.Canvas).fitWidth = true;

            this.node.getComponent(cc.Canvas).fitHeight=  false;

        }

    }

}

上一篇 下一篇

猜你喜欢

热点阅读