Hello guys,
I have an explosion class with 15 image in it. How do I clear the array of images after it is used since simply removing the object doesn't solve the heap space error after using the explosion a few time.
Thank You
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | public NukeExplosion () { //initialize the array of blue explosion pictures nukeExplosion = new GreenfootImage[ 15 ]; //filling the array with pictures for ( int i = 1 ; i <= 15 ; i++) { nukeExplosion[i - 1 ] = new GreenfootImage ( "nukeExplosion/" + i + ".png" ); } } /** * Act - do whatever the NukeExplosion wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { //add one to the act counter every act actCounter ++; //if statement that changes the picture every 5 act if (actCounter == 5 ) { //set act acounter to zero actCounter = 0 ; //set image of explosion setImage(nukeExplosion[curIndex]); //if statement that adds to the curIndex if it isn't at 14 if (!(curIndex == 14 )) { curIndex++; } } //if curIndex is 14 then it removes the explosion if (curIndex == 14 ) { SpaceWorld m = (SpaceWorld)getWorld(); m.removeObject( this ); } } |