java - Why is my array still NULL -
i attempting create simple way lay out tiles game.
how ever new java , oop, reason variables in array still null after assigned variables them via loop.
what have done wrong, why array still null? thanks.
stages stage1 = new stages(); public void stage1init() { stage1.stagew = 30; stage1.stageh = 30; stage1.tilesize = 100; stage1.stagestartx = 2; stage1.stagestarty = 24; //layout stage1 int w = stage1.stageh; int h = stage1.stagew; for(int = 0; < h; i++) { for(int j = 0; j < w; j++) { stage1.tilepositionx[i][j] = 100 * j; stage1.tilepositiony[i][j] = 100 * j; } } } //draw current stage public void drawstage1() { int w = stage1.stageh; int h = stage1.stagew; for(int = 0; < h; i++) { for(int j = 0; j < w; j++) { savecurrenttransform(); translate(stage1.tilepositionx[i][j], stage1.tilepositiony[i][j]); drawimage(grasstile, 0, 0, 100, 100); restorelasttransform(); } } }
thanks responses, needed assign size of array.
public void stage1init() { stage1.stagew = 30; stage1.stageh = 30; stage1.tilesize = 100; stage1.stagestartx = 2; stage1.stagestarty = 24; stage1.tilepositionx = new double[stage1.stagew][stage1.stageh]; stage1.tilepositiony = new double[stage1.stagew][stage1.stageh]; //layout stage1 int w = stage1.stageh; int h = stage1.stagew; for(int = 0; < h; i++) { for(int j = 0; j < w; j++) { stage1.tilepositionx[i][j] = 100 * j; //edit: looking simular, multipy following not j; stage1.tilepositiony[i][j] = 100 * i; } } }
Comments
Post a Comment