Aearnus
Aearnus

Reputation: 541

Java: Array syntax error when defining a new Rectangle

Ok, so I really can't figure this one out. I defined an array, playerPos, like this:

int[] playerPos = new int[]{32, 32};

and the first number is the x value, second is the y value. But, when I try to use it to define a rectangle, I get a syntax error here:

        for (int x = 0 ; x < 64; x++) {
        for (int y = 0 ; y < 64; y++) {
            switch(map[x][y]) {
            case 1:
                mapRects[x][y] = new Rect(x - playerPos[0])*64, (y - playerPos[1])*64, ((x - playerPos[0])*64)+64, ((y - playerPos[1])*64)+64);
                break;

            case 2:
                mapRects[x][y] = new Rect(x - playerPos[0])*64, ((y - playerPos[1])*64)-64, ((x - playerPos[0])*64)+64, ((y - playerPos[1])*64)+64);
                break;
            }
        }
    }

Wherever I say new Rect(), it gives me a syntax error on all the commas saying

Syntax error on token ",", [ expected

and on the last number, it says

Syntax error, insert "]" to complete Expression

I have no idea what is wrong. Help?

Upvotes: 0

Views: 154

Answers (2)

Cris Stringfellow
Cris Stringfellow

Reputation: 3808

You are missing a parenthesis on your Rect.

Upvotes: 1

imreal
imreal

Reputation: 10378

It is a parentheses problem:

new Rect(x - playerPos[0])*64 ...

You probably need to add an opening one like this:

new Rect((x - playerPos[0])*64 ...

Upvotes: 5

Related Questions