zoukankan      html  css  js  c++  java
  • cocos 2dx 通过循环实现界面图形的摆放

    首先创建一个一维数组

    this.starSprites = new Array();

    然后知道星星的间距和坐标后通过如下代码实现位置的摆放

    for(var i = 0; i < 6; i++)
    {
    this.starSprites[i] = new cc.Sprite(res.Stars02_png);
    this.starSprites[i].attr({
    x: (975 + 40*i),
    y: size.height-27,
    });
    this.addChild(this.starSprites[i], 0);
    }



    取代了如下代码
    this.starSprite1 = new cc.Sprite(res.Stars02_png);
    this.starSprite1.attr({
    x: 975,
    y: size.height-27,
    });
    this.addChild(this.starSprite1, 0);

    //add stars 2
    this.starSprite2 = new cc.Sprite(res.Stars02_png);
    this.starSprite2.attr({
    x: 1015,
    y: size.height-27,
    });
    this.addChild(this.starSprite2, 0);


    //add stars02 3
    this.starSprite3 = new cc.Sprite(res.Stars02_png);
    this.starSprite3.attr({
    x: 1055,
    y: size.height-27,
    });
    this.addChild(this.starSprite3, 0);


    //add stars02 4
    this.starSprite4 = new cc.Sprite(res.Stars02_png);
    this.starSprite4.attr({
    x: 1095,
    y: size.height-27,
    });
    this.addChild(this.starSprite4, 0);


    //add stars02 5
    this.starSprite5 = new cc.Sprite(res.Stars02_png);
    this.starSprite5.attr({
    x: 1135,
    y: size.height-27,
    });
    this.addChild(this.starSprite5, 0);


    //add stars02 6
    this.starSprite6 = new cc.Sprite(res.Stars02_png);
    this.starSprite6.attr({
    x: 1175,
    y: size.height-27,
    });
    this.addChild(this.starSprite6, 0);
  • 相关阅读:
    利用Telnet来模拟Http请求 有GET和POST两种
    WebConfig特殊字符的转义!
    userprofile同步用户失败的原因和解决方案
    linux mysql表名大小写
    web.py 中文模版报错
    docker 开启远程
    web.py 笔记
    python 安装influxdb-python
    安装pip
    influxdb 命令
  • 原文地址:https://www.cnblogs.com/fenr9/p/5166926.html
Copyright © 2011-2022 走看看