0
\$\begingroup\$

I am trying to write some code in Java for drawing sprites on a BufferedImage.

As of now I have each sprite in a single dimension array. However this is not good for my game because each sprite would only have one image for their sprite.

I would like each sprite to be animated meaning there would be more images to be stored. I have tried using two dimensional arrays for this but I keep running into the same issue with only one frame being stored.

What would be the proper way to solve this?

int[][] pxArry;
this.pxArry = new int[][]{
    new int [pxArry.length],
    new int [pxArry[1].length]
};
for(int i = 0; i < pxArry[0].length; i++)
    for(int i2 = 0; i2 < pxArry[1].length; i2++){
        this.pxArry[1][i2] = pxArry[1][i2];
    }
\$\endgroup\$
0
\$\begingroup\$

I do not really understand how your code works, especially the initialisation of the this.pxArray, but I can see that you never use the iterator i of the first loop in the inner loop.

Try with this :

for(int i = 0; i < pxArry[0].length; i++)
{
    for(int i2 = 0; i2 < pxArry[i].length; i2++){
        this.pxArry[i][i2] = pxArry[i][i2];
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.