2012-03-06 15 views
0

10レベル、2コイン、階段、バックグラウンドミュージック、モンスター、スパイクのセットを持つj2meゲームを作成しています。私はゲームの第2レベルになると、私はこのエラーです、私はこれはメモリが不足しているため、私は....とにかく私はこのエラーが発生するのを防ぐために私のコードを改善することができますこれを修正できますか?j2me:キャッチされない例外:java.lang.OutOfMemoryError(スタックトレースが不完全)

public class QuatschCanvas 
    extends GameCanvas 
    implements Runnable { 

/** 
* @return the points 
* 
* WHAT HAS TO BE DONE TO THE GAME 
* fix the door bug for all the levels after level 1 
* add 2 more coins 
* make the coins appear and disappear at different times but in the same place 
* add music to game 
* add sound when you hit a wall or die 
* add methods to fix up the code and make it look nice 
* fix record store to highest score 
* get game going back to main menu when finished 
* add animation to the main menu 
*/ 
public boolean mTrucking; 
private LayerManager mLayerManager; 
private TiledLayer mAtmosphere, mBackground, mCollisionBackground, mCollisionDoor; 
private int mAnimatedIndex; 
private Sprite mQuatsch, mCoin,mCoin2, mMonster, mKey, mStairs, mSpikesUp, mSpikesDown; 
private Graphics graphics; 
Image gameOver, youWin; 
private static int mState, mDirection, dState; 
private static final int kStanding = 1; 
private static final int kRunning = 2; 
private static final int kRunningUp = 3; 
private static final int kRunningDown = 4; 
private static final int kCoinSpin = 5; 
private static final int kMonsterMoveUp = 6; 
private static final int kMonsterMoveDown = 7; 
private static final int kLeft = 1; 
private static final int kRight = 2; 
private static final int kUp = 3; 
private static final int kDown = 4; 
private static int lives = 3; 
private static int coins = 0; 
private static int points = 0; 
public static int currentLevel = 1; 
public static int countForLevels = 0; 
private static int keys = 0; 
private static final int[] kRunningSequence = {0, 1, 0, 2}; 
private static final int[] kStandingSequence = {0}; 
private static final int[] kRunningSequenceUp = {3, 4, 3, 5}; 
private static final int[] kRunningSequenceDown = {6, 7, 6, 8}; 
private static final int[] kCoinSpinning = {0, 1, 2, 3, 4, 5}; 
private static final int[] kMonsterDown = {0, 1, 2, 1}; 
private static final int[] kMonsterUp = {9, 10, 11, 10}; 
private static int infinateLoop, spikeLoop; 

public QuatschCanvas(String quatschImageName, 
     String atmosphereImageName, String backgroundImageName, String coinName, String monsterName, 
     String keyName, String stairsName, String spikesNameUp, String spikesNameDown) throws IOException { 
    super(true); 

    // Create a LayerManager. 
    mLayerManager = new LayerManager(); 
    int w = getWidth(); 
    int h = getHeight(); 
    mLayerManager.setViewWindow(96, 0, w, h); 

    createBackground(backgroundImageName, 0); 
    createAtmosphere(atmosphereImageName); 
    createQuatsch(quatschImageName); 
    createCoin(coinName); 
    createSecondCoin(coinName); 
    createMonster(monsterName); 
    createKey(keyName); 
    createStairs(stairsName); 
    createSpikesUp(spikesNameUp); 
    createSpikesDown(spikesNameDown); 

    gameOver = Image.createImage("/game-over.png"); 
    youWin = Image.createImage("/you-win.png"); 
} 

private void createBackground(String backgroundImageName, int level) 
     throws IOException { 
    // Create the tiled layer. 
    Image backgroundImage = Image.createImage(backgroundImageName); 

    mCollisionDoor = new TiledLayer(8, 7, backgroundImage, 96, 96); 
    mCollisionDoor.setPosition(12, 0); 
    for (int i = 0; i < doorMap[level].length; i++) { 
     int column = i % 8; 
     int row = (i - column)/8; 
     mCollisionDoor.setCell(column, row, doorMap[level][i]); 
    } 
    mAnimatedIndex = mCollisionDoor.createAnimatedTile(8); 
    //mCollisionBackground.setCell(3, 1, mAnimatedIndex); 
    mLayerManager.append(mCollisionDoor); 

    mBackground = new TiledLayer(8, 7, backgroundImage, 96, 96); 
    mBackground.setPosition(12, 0); 
    for (int i = 0; i < map[level].length; i++) { 
     int column = i % 8; 
     int row = (i - column)/8; 
     mBackground.setCell(column, row, map[level][i]); 
    } 
    mAnimatedIndex = mBackground.createAnimatedTile(8); 
    // mBackground.setCell(3, 1, mAnimatedIndex); 
    mLayerManager.append(mBackground); 

    mCollisionBackground = new TiledLayer(8, 7, backgroundImage, 96, 96); 
    mCollisionBackground.setPosition(12, 0); 
    for (int i = 0; i < collsionMap[level].length; i++) { 
     int column = i % 8; 
     int row = (i - column)/8; 
     mCollisionBackground.setCell(column, row, collsionMap[level][i]); 
    } 
    mAnimatedIndex = mCollisionBackground.createAnimatedTile(8); 
    //mCollisionBackground.setCell(3, 1, mAnimatedIndex); 
    mLayerManager.append(mCollisionBackground); 


} 

private void createAtmosphere(String atmosphereImageName) 
     throws IOException { 
    // Create the atmosphere layer 
    Image atmosphereImage = Image.createImage(atmosphereImageName); 
    mAtmosphere = new TiledLayer(8, 1, atmosphereImage, 
      atmosphereImage.getWidth(), atmosphereImage.getHeight()); 
    mAtmosphere.fillCells(0, 0, 8, 1, 1); 
    mAtmosphere.setPosition(0, 192); 

    mLayerManager.insert(mAtmosphere, 0); 
} 

private void createQuatsch(String quatschImageName) 
     throws IOException { 
    // Create the sprite. 
    Image quatschImage = Image.createImage(quatschImageName); 
    mQuatsch = new Sprite(quatschImage, 48, 48); 
    mQuatsch.setPosition(96 + (getWidth() - 48)/2, 100); 
    mQuatsch.defineReferencePixel(24, 24); 
    setDirection(kLeft); 
    setState(kStanding); 
    mLayerManager.insert(mQuatsch, 1); 
} 

private void createKey(String keyName) 
     throws IOException { 
    // Create the sprite. 
    Image keyImage = Image.createImage(keyName); 
    mKey = new Sprite(keyImage, 48, 48); 
    mKey.setPosition(250, 110); 
    mKey.defineReferencePixel(24, 24); 
    setState(kStanding); 
    mLayerManager.insert(mKey, 0); 
} 

private void createSpikesUp(String spikesNameUp) 
     throws IOException { 
    // Create the sprite. 
    Image spikesImageUp = Image.createImage(spikesNameUp); 
    mSpikesUp = new Sprite(spikesImageUp, 48, 48); 
    //mSpikes.setPosition(200, 110); 
    mSpikesUp.defineReferencePixel(24, 24); 
    setState(kStanding); 
    mLayerManager.insert(mSpikesUp, 0); 
} 

private void createSpikesDown(String spikesNameDown) 
     throws IOException { 
    // Create the sprite. 
    Image spikesImageDown = Image.createImage(spikesNameDown); 
    mSpikesDown = new Sprite(spikesImageDown, 48, 48); 
    //mSpikes.setPosition(200, 110); 
    mSpikesDown.defineReferencePixel(24, 24); 
    setState(kStanding); 
    mLayerManager.insert(mSpikesDown, 0); 
} 

private void createStairs(String stairsName) 
     throws IOException { 
    // Create the sprite. 
    Image stairsImage = Image.createImage(stairsName); 
    mStairs = new Sprite(stairsImage, 48, 48); 
    mStairs.setPosition(130, 520); 
    mStairs.defineReferencePixel(24, 24); 
    setState(kStanding); 
    mLayerManager.insert(mStairs, 0); 
} 

private void createCoin(String coinName) 
     throws IOException { 
    // Create the atmosphere layer 
    Image coinImage = Image.createImage(coinName); 
    mCoin = new Sprite(coinImage, 48, 48); 
    mCoin.setPosition(500, 150); 
    mCoin.defineReferencePixel(24, 24); 
    setState(kCoinSpin); 
    mLayerManager.insert(mCoin, 0); 
} 

private void createSecondCoin(String coinName) 
     throws IOException { 
    // Create the atmosphere layer 
    Image coinImage = Image.createImage(coinName); 
    mCoin2 = new Sprite(coinImage, 48, 48); 
    mCoin2.setPosition(250, 220); 
    mCoin2.defineReferencePixel(24, 24); 
    setState(kCoinSpin); 
    mLayerManager.insert(mCoin2, 0); 
} 

private void createMonster(String monsterName) 
     throws IOException { 
    // Create the atmosphere layer 
    Image monsterImage = Image.createImage(monsterName); 
    mMonster = new Sprite(monsterImage, 48, 48); 
    mMonster.setPosition(520, 500); 
    mMonster.defineReferencePixel(24, 24); 
    setDirection(kUp); 
    setState(kMonsterMoveUp); 
    mLayerManager.insert(mMonster, 0); 
} 

public void start() { 
    mTrucking = true; 
    Thread t = new Thread(this); 
    t.start(); 
} 

public void run() { 
    int w = getWidth(); 
    int h = getHeight(); 
    Graphics g = getGraphics(); 
    int frameCount = 0; 
    int factor = 2; 
    int animatedDelta = 0; 

InputStream is = getClass().getResourceAsStream("/audio/mainsong.mp3"); 
Player p; 
    try { 
     p = Manager.createPlayer(is, "audio/mpeg"); 
     p.setLoopCount(-1); 
     p.start(); 
    } catch (IOException ex) { 
     ex.printStackTrace(); 
    } catch (MediaException ex) { 
     ex.printStackTrace(); 
    } 






    while (mTrucking) { 
     // create timer for the dragon to move up the map 
     Timer aTimer = new Timer(); 
     TimerTask firstTask = new TimerTask() { 

      public void run() { 
       setDragonState(kMonsterMoveUp); 
       mMonster.move(0, -3); 
       mSpikesUp.setVisible(true); 
       mSpikesDown.setVisible(false); 
       mCoin.setVisible(false); 
       mCoin.setVisible(true); 
      } 
     }; 
     // create a timer for the dragon to move down the map 
     TimerTask secondTask = new TimerTask() { 

      public void run() { 
       setDragonState(kMonsterMoveDown); 
       mMonster.move(0, 3); 
       mSpikesUp.setVisible(false); 
       mSpikesDown.setVisible(true); 
       mCoin.setVisible(true); 
       mCoin.setVisible(false); 
      } 
     }; 

     // continueos loop so the dragon will keep moving up and down the map 
     if (infinateLoop >= 0 && infinateLoop < 50) { 
      aTimer.schedule(firstTask, 1000); 
      infinateLoop = infinateLoop + 1; 
      mMonster.nextFrame(); 
     } else if (infinateLoop >= 50 && infinateLoop < 100) { 
      aTimer.schedule(secondTask, 1000); 
      infinateLoop = infinateLoop + 1; 
      mMonster.nextFrame(); 
     } else { 
      infinateLoop = 0; 
     } 


     // what to do if the player hits a coin 

     if (mQuatsch.collidesWith(mCoin, true)) {   
      mCoin.setVisible(false); 
      coins++; 
      setPoints(getPoints() + 20); 
     } 

     if (mQuatsch.collidesWith(mCoin2, true)) { 
      mCoin2.setVisible(false); 
      coins++; 
      setPoints(getPoints() + 20); 
     } 

     if (mQuatsch.collidesWith(mStairs, true)) { 
      aTimer.cancel(); 
      firstTask.cancel(); 
      secondTask.cancel(); 
      countForLevels++; 
      if(countForLevels<10){ 

      for (int i = 0; i < map[countForLevels].length; i++) { 
       int column = i % 8; 
       int row = (i - column)/8; 
       mBackground.setCell(column, row, map[countForLevels][i]); 
      } 
      for (int i = 0; i < collsionMap[countForLevels].length; i++) { 
       int column = i % 8; 
       int row = (i - column)/8; 
       mCollisionBackground.setCell(column, row, collsionMap[countForLevels][i]); 
      } 
      for (int i = 0; i < doorMap[countForLevels].length; i++) { 
       int column = i % 8; 
       int row = (i - column)/8; 
       mCollisionDoor.setCell(column, row, doorMap[countForLevels][i]); 
      } 
      mCollisionDoor.setVisible(true); 
      mKey.setVisible(true); 
      mCoin.setVisible(true); 
      mCoin2.setVisible(true); 
      mLayerManager.append(mBackground); 
      mLayerManager.append(mCollisionBackground); 
      mLayerManager.append(mCollisionDoor); 

      //resetItems(int bg_x, int bg_y, int s_x, int s_y, int k_x, int k_y, int su_x, int su_y, int sd_x, int sd_y, int m_x, int m_y, int c_x, int c_y) 
      if (countForLevels == 1) { 
       resetItems(-450, -300, -40, 40, 150, -70, -50, 228, -158, 180, 10000, 10000, -330, -170, -300, 70);//170 
      } else if (countForLevels == 2) { 
       resetItems(12, 0, 226, 315, 420, 300, 520, 144, 520, 96, 10000, 10000, 615, 115, 605, 515);//115 
      } else if (countForLevels == 3) { 
       resetItems(-450, -300, -330, 200, 150, -70, -230, -156, -230, -204, 10000, 10000, -330, -170, -300, -170); 
      } else if (countForLevels == 4) { 
       resetItems(12, 0, 606, 120, 420, 100, 10000, 10000, 10000, 10000, 410, 344, 320, 330, 320, 300); 
      } else if (countForLevels == 5) { 
       resetItems(-450, -300, -332, -72, -332, 200, 10000, 10000, 10000, 10000, -137, 130, 150, -70, 100, -70);//mite be -115 n 300, 200 , 100 
      } else if (countForLevels == 6) { 
       resetItems(12, 0, 130, 505, 250, 110, 10000, 10000, 10000, 10000, 410, 300, 615, 215, 605, 215); 
      } else if (countForLevels == 7) { 
       resetItems(-450, -300, -332, -175, -50, 200, -98, 228, -98, 180, 10000, 10000, -130, -170, -100, -170); 
      } else if (countForLevels == 8) { 
       resetItems(12, 0, 606, 215, 620, 425, 10000, 10000, 10000, 10000, 520, 465, 620, 525, 660, 525); 
      } else if (countForLevels == 9) { 
       resetItems(-450, -300, -332, -175, 150, -170, -28, 228, -28, 180, 10000, 10000, -40, -40, -20, -40); 
      } 
      } 
     } 

     if (mQuatsch.collidesWith(mSpikesUp, true)) { 
      if (countForLevels == 1) { 
       resetItems(-450, -300, -40, 40, 150, -70, -50, 228, -158, 180, 10000, 10000, -330, -170, -300, -170); 
      } else if (countForLevels == 2) { 
       resetItems(12, 0, 226, 315, 420, 300, 520, 144, 520, 96, 10000, 10000, 615, 115, 605, 115); 
      } else if (countForLevels == 3) { 
       resetItems(-450, -300, -330, 200, 150, -70, -230, -156, -230, -204, 10000, 10000, -330, -170, -300, -170); 
      } else if (countForLevels == 4) { 
       resetItems(12, 0, 606, 120, 420, 100, 10000, 10000, 10000, 10000, 410, 344, 320, 330, 320, 300); 
      } else if (countForLevels == 5) { 
       resetItems(-450, -300, -332, -72, -332, 200, 10000, 10000, 10000, 10000, -137, 130, 150, -70, 100, -70);//mite be -115 n 300, 200 , 100 
      } else if (countForLevels == 6) { 
       resetItems(12, 0, 130, 505, 250, 110, 10000, 10000, 10000, 10000, 410, 300, 615, 215, 605, 215); 
      } else if (countForLevels == 7) { 
       resetItems(-450, -300, -332, -175, -50, 200, -98, 228, -98, 180, 10000, 10000, -130, -170, -100, -170); 
      } else if (countForLevels == 8) { 
       resetItems(12, 0, 606, 215, 620, 425, 10000, 10000, 10000, 10000, 520, 465, 620, 525, 660, 525); 
      } else if (countForLevels == 9) { 
       resetItems(-450, -300, -332, -175, 150, -170, -28, 228, -28, 180, 10000, 10000, -40, -40, -20, -40); 
      } 
      lives--; 
     } 

     if (mQuatsch.collidesWith(mSpikesDown, true)) { 
      if (countForLevels == 1) { 
       resetItems(-450, -300, -40, 40, 150, -70, -50, 228, -158, 180, 10000, 10000, -330, -170, -300, -170); 
      } else if (countForLevels == 2) { 
       resetItems(12, 0, 226, 315, 420, 300, 520, 144, 520, 96, 10000, 10000, 615, 115, 605, 115); 
      } else if (countForLevels == 3) { 
       resetItems(-450, -300, -330, 200, 150, -70, -230, -156, -230, -204, 10000, 10000, -330, -170, -300, -170); 
      } else if (countForLevels == 4) { 
       resetItems(12, 0, 606, 120, 420, 100, 10000, 10000, 10000, 10000, 410, 344, 320, 330, 320, 300); 
      } else if (countForLevels == 5) { 
       resetItems(-450, -300, -332, -72, -332, 200, 10000, 10000, 10000, 10000, -137, 130, 150, -70, 100, -70);//mite be -115 n 300, 200 , 100 
      } else if (countForLevels == 6) { 
       resetItems(12, 0, 130, 505, 250, 110, 10000, 10000, 10000, 10000, 410, 300, 615, 215, 605, 215); 
      } else if (countForLevels == 7) { 
       resetItems(-450, -300, -332, -175, -50, 200, -98, 228, -98, 180, 10000, 10000, -130, -170, -100, -170); 
      } else if (countForLevels == 8) { 
       resetItems(12, 0, 606, 215, 620, 425, 10000, 10000, 10000, 10000, 520, 465, 620, 525, 660, 525); 
      } else if (countForLevels == 9) { 
       resetItems(-450, -300, -332, -175, 150, -170, -28, 228, -28, 180, 10000, 10000, -40, -40, -20, -40); 
      } 
      lives--; 
     } 

     // what to do if a player hits a key 
     if (mQuatsch.collidesWith(mKey, true)) { 
      mKey.setVisible(false); 
      System.out.println(keys); 
      keys = keys + 1; 
      setPoints(getPoints() + 50); 
      System.out.println(keys); 
     } 

     // what to do if the player hits a monster 
     if (mQuatsch.collidesWith(mMonster, true)) { 
      if (countForLevels == 1) { 
       resetItems(-450, -300, -40, 40, 150, -70, -50, 228, -158, 180, 10000, 10000, -330, -170, -300, -170); 
      } else if (countForLevels == 2) { 
       resetItems(12, 0, 226, 315, 420, 300, 520, 144, 520, 96, 10000, 10000, 615, 115, 605, 115); 
      } else if (countForLevels == 3) { 
       resetItems(-450, -300, -330, 200, 150, -70, -230, -156, -230, -204, 10000, 10000, -330, -170, -300, -170); 
      } else if (countForLevels == 4) { 
       resetItems(12, 0, 606, 120, 420, 100, 10000, 10000, 10000, 10000, 410, 344, 320, 330, 320, 300); 
      } else if (countForLevels == 5) { 
       resetItems(-450, -300, -332, -72, -332, 200, 10000, 10000, 10000, 10000, -137, 130, 150, -70, 100, -70);//mite be -115 n 300, 200 , 100 
      } else if (countForLevels == 6) { 
       resetItems(12, 0, 130, 505, 250, 110, 10000, 10000, 10000, 10000, 410, 300, 615, 215, 605, 215); 
      } else if (countForLevels == 7) { 
       resetItems(-450, -300, -332, -175, -50, 200, -98, 228, -98, 180, 10000, 10000, -130, -170, -100, -170); 
      } else if (countForLevels == 8) { 
       resetItems(12, 0, 606, 215, 620, 425, 10000, 10000, 10000, 10000, 520, 465, 620, 525, 660, 525); 
      } else if (countForLevels == 9) { 
       resetItems(-450, -300, -332, -175, 150, -170, -28, 228, -28, 180, 10000, 10000, -40, -40, -20, -40); 
      } 
      lives--; 
     } 

     if (isShown()) { 
      int keyStates = getKeyStates(); 
      if ((keyStates & LEFT_PRESSED) != 0) { 
       setDirection(kLeft); 
       movingCharacter(kRunning, 10, 0, -10, 0); 

      } else if ((keyStates & RIGHT_PRESSED) != 0) { 
       setDirection(kRight); 
       movingCharacter(kRunning, -10, 0, 10, 0); 

      } else if ((keyStates & UP_PRESSED) != 0) { 
       movingCharacter(kRunningUp, 0, 10, 0, -10); 

      } else if ((keyStates & DOWN_PRESSED) != 0) { 
       movingCharacter(kRunningDown, 0, -10, 0, 10); 

      } else { 
       setState(kStanding); 
       mCoin.nextFrame(); 
       mCoin2.nextFrame(); 
      } 

      frameCount++; 
      if (frameCount % factor == 0) { 
       int delta = 1; 
       if (frameCount/factor < 10) { 
        delta = -1; 
       } 
       mAtmosphere.move(delta, 0); 
       if (frameCount/factor == 20) { 
        frameCount = 0; 
       } 

       mBackground.setAnimatedTile(mAnimatedIndex, 
         8 + animatedDelta++); 
       if (animatedDelta == 3) { 
        animatedDelta = 0; 
       } 
      } 

      g.setColor(0x5b1793); 
      g.fillRect(0, 0, w, h); 

      mLayerManager.paint(g, 0, 0); 

      flushGraphics(); 
     } 

     try { 
      Thread.sleep(80); 
     } catch (InterruptedException ie) { 
     } 

     if (lives == 0) { 
      stop(); 
      g.drawImage(gameOver,10,50,Graphics.TOP | Graphics.LEFT); 
      repaint(); 
     } 

     if(countForLevels == 10){ 
      stop(); 
      g.drawImage(youWin,10,50,Graphics.TOP | Graphics.LEFT); 
      repaint(); 
     } 
    } 
    //String pointsString = Integer.toString(points); 
    //String levelString = Integer.toString(level); 

    //mScoreListener.collectItems(pointsString, levelString); 

    System.out.println("Points = " + getPoints() + "\nLevel = " + currentLevel); 
} 

public void movingCharacter(int state, int x, int y, int a, int b) { 
    setState(state); 
    mBackground.move(x, y); 
    mCollisionBackground.move(x, y); 
    mCollisionDoor.move(x, y); 
    mAtmosphere.move(x, y); 
    mCoin.move(x, y); 
    mCoin2.move(x, y); 
    mStairs.move(x, y); 
    mMonster.move(x, y); 
    mKey.move(x, y); 
    mQuatsch.nextFrame(); 
    mCoin.nextFrame(); 
    mCoin2.nextFrame(); 
    mSpikesUp.move(x, y); 
    mSpikesDown.move(x, y); 
    // if the player hits a wall 
    if (mQuatsch.collidesWith(mCollisionBackground, true)) { 
     mBackground.move(a, b); 
     mCollisionBackground.move(a, b); 
     mCollisionDoor.move(a, b); 
     mAtmosphere.move(a, b); 
     mCoin.move(a, b); 
     mCoin2.move(a, b); 
     mStairs.move(a, b); 
     mKey.move(a, b); 
     mMonster.move(a, b); 
     mSpikesUp.move(a, b); 
     mSpikesDown.move(a, b); 
    } 
    // if the user hits a door with a key and without a key 
    if (mQuatsch.collidesWith(mCollisionDoor, true)) { 
     if (keys > 0) { 
      System.out.println("hit wall with key" + doorMap[0][34]); 
      //doorMap[0][34] = 0; 
      mCollisionDoor.setVisible(false); 
      keys--; 
      mLayerManager.append(mCollisionDoor); 
      //mLayerManager.remove(mCollisionDoor); 
      setPoints(getPoints() + 10); 
      System.out.println("hit wall with key after changes" + doorMap[0][34]); 
     } else { 
      System.out.println("hit wall without key"); 
      mBackground.move(a, b); 
      mCollisionBackground.move(a, b); 
      mCollisionDoor.move(a, b); 
      mAtmosphere.move(a, b); 
      mCoin.move(a, b); 
      mCoin2.move(a, b); 
      mStairs.move(a, b); 
      mMonster.move(a, b); 
      mKey.move(a, b); 
      mSpikesUp.move(a, b); 
      mSpikesDown.move(a, b); 
     } 
    } 
} 

public void resetItems(int bg_x, int bg_y, int s_x, int s_y, int k_x, int k_y, int su_x, int su_y, int sd_x, int sd_y, int m_x, int m_y, int c_x, int c_y, int c2_x, int c2_y) { 
    mBackground.setPosition(bg_x, bg_y); 
    mCollisionBackground.setPosition(bg_x, bg_y); 
    mCollisionDoor.setPosition(bg_x, bg_y); 
    mStairs.setPosition(s_x, s_y); 
    mKey.setPosition(k_x, k_y); 
    mSpikesUp.setPosition(su_x, su_y); 
    mSpikesDown.setPosition(sd_x, sd_y); 
    mMonster.setPosition(m_x, m_y); 
    mCoin.setPosition(c_x, c_y); 
    mCoin2.setPosition(c2_x, c2_y); 
} 

public void stop() { 
    mTrucking = false; 

} 



public void setVisible(int layerIndex, boolean show) { 
    Layer layer = mLayerManager.getLayerAt(layerIndex); 
    layer.setVisible(show); 
} 

public boolean isVisible(int layerIndex) { 
    Layer layer = mLayerManager.getLayerAt(layerIndex); 
    return layer.isVisible(); 
} 

private void setDirection(int newDirection) { 
    if (newDirection == mDirection) { 
     return; 
    } 
    if (mDirection == kLeft) { 
     mQuatsch.setTransform(Sprite.TRANS_MIRROR); 
    } else if (mDirection == kRight) { 
     mQuatsch.setTransform(Sprite.TRANS_NONE); 
    } 
    mDirection = newDirection; 
} 

    public static int getPoints() { 
    return points; 
} 

/** 
* @param aPoints the points to set 
*/ 
public static void setPoints(int aPoints) { 
    points = aPoints; 
} 

private void setState(int newState) { 
    if (newState == mState) { 
     return; 
    } 
    switch (newState) { 
     case kStanding: 
      mQuatsch.setFrameSequence(kStandingSequence); 
      mQuatsch.setFrame(0); 
      break; 
     case kRunning: 
      mQuatsch.setFrameSequence(kRunningSequence); 
      break; 
     case kRunningUp: 
      mQuatsch.setFrameSequence(kRunningSequenceUp); 
      break; 
     case kRunningDown: 
      mQuatsch.setFrameSequence(kRunningSequenceDown); 
      break; 
     case kCoinSpin: 
      mQuatsch.setFrameSequence(kCoinSpinning); 
      break; 
     case kMonsterMoveUp: 
      mMonster.setFrameSequence(kMonsterUp); 
      break; 
     case kMonsterMoveDown: 
      mMonster.setFrameSequence(kMonsterDown); 
      break; 
     default: 
      break; 
    } 
    mState = newState; 
} 

private void setDragonState(int newState) { 
    if (newState == dState) { 
     return; 
    } 
    switch (newState) { 
     case kStanding: 
      mMonster.setFrameSequence(kStandingSequence); 
      mMonster.setFrame(0); 
      break; 
     case kMonsterMoveUp: 
      mMonster.setFrameSequence(kMonsterUp); 
      break; 
     case kMonsterMoveDown: 
      mMonster.setFrameSequence(kMonsterDown); 
      break; 
     default: 
      break; 
    } 
dState = newState; 

}

おかげ

+2

私は申し訳ありませんが、これはofftopicです。 FAQを参照してください: "あなたの知識の中で、コードは機能しますか?"それは動作しないので、StackOverflow上にあるはずです。 –

+0

yaコードは動作しますが、2番目のコインとサウンドを取り出すとうまく動作しますが、それらを入れたらレベル3までしか動作せず、次にこのエラーがスローされます –

+0

コードにフィードバックが必要な場合はここに質問があります。あなたのコードを修正するのに役立つ場合、それはスタックオーバーフローに属しています、私は今この問題を移行しました。 – sepp2k

答えて

0

それは "フル" になっているLayerManagerです。

各レベルの間で、remove(int layer)メソッドを使用してクリアまたは空にすることをお勧めします。

関連する問題