-1

Hey i am writing a game when there are bunch of textures that changes locations, but i want to check that they are not drawing over other textures, i tried to write a code for checking it but its not working well.

Here is the code i tried:

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;
            }
        }
    }

How to fix it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3419789
  • 27
  • 1
  • 8

2 Answers2

0

this is confusing,

while(isLaping = true){

you mean it

while(isLaping == true){

or

while(isLaping){

while(isLaping=true); isLaping never is false at the moment evaluate while because asign true every time

Angel Angel
  • 19,670
  • 29
  • 79
  • 105
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – djv Dec 20 '14 at 19:46
  • @Verdoline I do not intend to criticize the author, simply emphasize if this is what you want or a simple mistake, if an error can your code does not work as desired and that's the solution, while(isLaping=true); isLaping never is false at the moment evaluate while because asign true every time – Angel Angel Dec 20 '14 at 19:57
  • You can put that comment right in the "answer" to make it more of an answer than a critique / question. – djv Dec 20 '14 at 19:58
  • @Verdolino did not think to put it that way, they could be interpreted as a critique of the author, thanks – Angel Angel Dec 20 '14 at 20:02
0

I tried again to do so with your tip but the circle are getting crazy and changes places every second

this is the code i have been trying.

            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);
    }
user3419789
  • 27
  • 1
  • 8