class ButtonImages { PImage[][] object, icon; ButtonImages() { object = new PImage[4][]; icon = new PImage[4][]; } int nameToIndex(String name) { int index=0; if(name == "dodon") { index = 0; } else if(name == "horba") { index = 1; } else if(name == "kuka") { index = 2; } else if(name == "popo") { index = 3; } return index; } PImage[] getObjectImages(String name, int object_num) { int index = nameToIndex(name); if( object[index] == null ) { object[index] = new PImage[object_num + 3]; // キャラ別のオブジェクト + 共通オブジェクト3つ for(int i=0 ; i < object_num ; i++) { object[index][i] = loadImage(name + "/object_" + nf(i, 2) + ".png"); } // 残り3つは共通フォルダから for(int i=0 ; i < 3 ; i++) { object[index][object_num+i] = loadImage("common/object_"+nf(i,2)+".png"); // インデックスに毎回+object_numする } } return object[index]; } PImage[] getIconImages(String name, int object_num) { int index = nameToIndex(name); if( icon[index] == null ) { icon[index] = new PImage[object_num + 3]; // キャラ別のアイコン + 共通アイコン3つ for(int i=0 ; i < object_num ; i++) { icon[index][i] = loadImage(name + "/icon_" + nf(i, 2) + ".png"); } // 残り3つは共通フォルダから for(int i=0 ; i < 3 ; i++) { icon[index][object_num+i] = loadImage("common/icon_"+nf(i,2)+".png"); // インデックスに毎回+object_numする } } return icon[index]; } }