java - How do I selectively reset an array's dimensions? -


this question has answer here:

i have abstract class sprite, which, in constructor, creates array individual sprites. constructor takes path of spritesheet, spritesheet type enum, , individual sprites' widths , heights. constructor takes path spritesheet, loads bufferedimage, , grabs individual sprites image load them array. here class:

package exosoft.zerfall;  public abstract class sprite extends main {     bufferedimage spritesheet = null;     bufferedimage[] sprites;     int spritewidth = 0;     int spriteheight = 0;      public enum sheettype {         single,         horizontal,         vertical,         rectangular     }     public sprite(sheettype type, string sheetpath, int spritewidth, int spriteheight) {         try {             spritesheet = imageio.read(new file(sheetpath));         } catch (ioexception e) {             e.printstacktrace();         }         switch(type) {         case horizontal:             sprites = new bufferedimage[spritesheet.getwidth() / spritewidth];             (int = 0; < spritesheet.getwidth() / spritewidth; i++) {                 sprites[i] = spritesheet.getsubimage(i * spritewidth, 0, spritewidth, spriteheight);             }             break;         case rectangular:             break;         case vertical:             sprites = new bufferedimage[spritesheet.getheight() / spriteheight];             (int = 0; < spritesheet.getheight() / spriteheight; i++) {                 sprites[i] = spritesheet.getsubimage(0, * spriteheight, spritewidth, spriteheight);             }             break;         default:             break;         }     } } 

what want allow bufferedimage[] sprites array add or remove dimension based on given sheettype. example, here switch statement i'd work:

switch(type) {     case horizontal:         sprites = new bufferedimage[spritesheet.getwidth() / spritewidth];         //load sprites one-dimensional array         break;     case rectangular:         sprites = new bufferedimage[spritesheet.getwidth() / spritewidth][spritesheet.getheight / spriteheight];         //load sprites two-dimensional array         break;     case vertical:         sprites = new bufferedimage[spritesheet.getheight() / spriteheight];         //load sprites one-dimensional array         break;     case single:         sprites = new bufferedimage();         //load sprite zero-dimensional bufferedimage         break;     default:         break; } 

the goal end array named sprites individual sprites contained, dimensions needed. @ possible? thank you.

what this:

bufferedimage[][] sprites=null;  case 0-dimension: sprites=new bufferedimage[1][1]; case 1-dimension: sprites=new bufferedimage[n][1] case 2-dimension: sprites=new bufferedimage[n][m] 

then

case 0-dimension: sprites[0][0]=new bufferedimage(....); case 1-dimension: for(i) sprites[i][0]=new bufferedimage() case 2-dimension: for(i) for(j) sprites[i][j]=new bufferedimage() 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -