检查纹理重叠

时间:2014-12-20 14:23:48

标签: android opengl-es libgdx

嘿,我正在写一个游戏,当有一堆纹理改变位置,但我想检查他们没有绘制其他纹理,我试图编写一个代码来检查它,但它不能正常工作。

这是我试过的代码:

circles.setPosition(new Vector2(r.nextInt(width-height/8*2)+height/8,
                                r.nextInt(height-height/8*2)+height/8),
                                i);

circl[i].set((float) (circles.getPosition(i).x+height/16),
             (float) (circles.getPosition(i).y+height/16),
              height/16);

    while(isLaping = true){

        System.out.println("in");

        for(int y = 0; y < circlesArray.length-1; y++){

            if(Intersector.overlaps(circl[y], circl[y+1])){

                circles.setPosition(new Vector2(r.nextInt(width-height/8*2)+height/8,
                                                r.nextInt(height-height/8*2)+height/8),
                                                i);

                circl[i].set((float) (circles.getPosition(i).x+height/16),
                             (float) (circles.getPosition(i).y+height/16),
                              height/16);
            }else{
                isLaping = false;
            }
        }
    }

如何解决?

2 个答案:

答案 0 :(得分:0)

这令人困惑,

while(isLaping = true){

你的意思是

while(isLaping == true){

while(isLaping){

而(isLaping = TRUE); isLaping从来都不是假的,因为每次都是真实的

答案 1 :(得分:0)

我再次尝试用你的提示这样做但是圈子变得疯狂并且每隔一秒发生变化

这是我一直在尝试的代码。

            for(int i = 0;i<circlesArray.length;i++)
        {
            if(circlesArray[i]>200)
            {
                changePosition(i);

            }
            circlesArray[i]++;
        }


    private void changePosition(int i)
{
    int s = 0;
    circles.setPosition(new Vector2(r.nextInt(width-height/12*2)+height/8,r.nextInt(height-height/12*2)+height/12),i);
    circl[i].set((float) (circles.getPosition(i).x+height/24),(float) (circles.getPosition(i).y+height/24),height/24);

    while (lap == true)
    {
    circles.setPosition(new Vector2(r.nextInt(width-height/12*2)+height/8,r.nextInt(height-height/12*2)+height/12),i);
    circl[i].set((float) (circles.getPosition(i).x+height/24),(float) (circles.getPosition(i).y+height/24),height/24);
    for(int y= i+1;y<circlesArray.length;y++)
    {
        if(circl[i].overlaps(circl[y]))
        {
            circles.setPosition(new Vector2(r.nextInt(width-height/12*2)+height/8,r.nextInt(height-height/12*2)+height/12),i);
            circl[i].set((float) (circles.getPosition(i).x+height/24),(float) (circles.getPosition(i).y+height/24),height/24);
            s=0;
        }
        else
        {
            s++;
        }
    }
    if(s == circlesArray.length)
        lap = false;
    }
    circlesArray[i] = 0;
    x[i] = r.nextInt(circleTexture.length);
    }