问答详情
源自:1-2 鱼尾巴摆动

为什么不把眼睛眨动的图片在baby对象里面初始化呢,这样main是不是显得更清晰?

babyObj.prototype.init = function () {

    this.x = canWidth * 0.5;

    this.y = canHeight * 0.5 ;

    //this.babyEye.src = "src/babyEye0.png";

    this.babyBody.src = "src/babyFade0.png";

    this.angle = 0;


    this.babyTailCount = 0;

    this.babyTailTimer = 0;

    for (var i = 0; i < 8; i++) {

        this.babyTail[i] = new Image();

        this.babyTail[i].src = "src/babyTail" + i + ".png";

    }


    this.babyEyeCount = 0;

    this.babyEyeTimer = 0;

    for (var i = 0; i < 2; i++) {

        this.babyEye[i] = new Image();

        this.babyEye[i].src =  "src/babyEye" + i + ".png";

    }  


提问者:慕无忌8111235 2016-07-24 22:11

个回答

  • qq_风龙_0
    2016-09-23 16:08:54

    在baby对象中使用,就是私有属性,放到main中就是全局变量,就看你怎么使用了

  • hk凯
    2016-08-03 11:05:14

    说的好,同问