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);
  • 相关阅读:
    相关术语随笔
    JDK简介和mac下安装和查看版本命令
    英语
    英语学习2
    英语学习-19.1
    为什么java是只有值传递而没有引用传递
    线程
    关于同步异步

    jdk动态代理实现原理总结
  • 原文地址:https://www.cnblogs.com/fenr9/p/5166926.html
Copyright © 2011-2022 走看看