2016-04-06 13 views
1

Also während ich ein bestehendes Framework modifiziere, versuche ich das Hintergrundbild zu ändern. Ich habe nicht nur das Bild aus dem Ordner Assets gelöscht, ich rufe das neue Hintergrundbild an. Aber aus irgendeinem Grund zeigt sich der alte HintergrundHintergrundbild wird nicht angezeigt

Hier wird das Bild geladen.

 public static void load() { 
      icLauncher = loadBitmap("ic_launcher_36",false); 
     dodgingfire_welcome = loadBitmap("dodgingfire_welcome.png", false); 
      block = loadBitmap("block.png", false); 
      cloud1 = loadBitmap("cloud1.png", true); 
      cloud2 = loadBitmap("cloud2.png", true); 
      duck = loadBitmap("duck.png", true); 
      grass = loadBitmap("grass.png", false); 

Hier wird die Methode aufgerufen.

 @Override 
     public void render(Painter g) { 
    g.drawImage(Assets.dodgingfire_welcome, 0, 0); 
      startButton.render(g); 
      scoreButton.render(g); 
     } 

Dies sind die vollen Klassen

package rect.draw.gametest.model.state; 

import android.view.MotionEvent; 

import rect.draw.gametest.Assets; 
import rect.draw.gametest.model.util.Painter; 
import rect.draw.gametest.model.util.UIButton; 


public class MenuState extends State { 
    private UIButton startButton, scoreButton; 

    @Override 
    public void init() { 
     startButton = new UIButton(316, 227, 484, 286, Assets.start, 
       Assets.startDown); 
     scoreButton = new UIButton(316, 300, 484, 359, Assets.score, 
       Assets.scoreDown); 
    } 

    @Override 
    public void update(float delta) { 
    } 

    @Override 
    public void render(Painter g) { 

     g.drawImage(Assets.dodgingfire_welcome, 0, 0); 
     startButton.render(g); 
     scoreButton.render(g); 
    } 

    @Override 
    public boolean onTouch(MotionEvent e, int scaledX, int scaledY) { 
     if (e.getAction() == MotionEvent.ACTION_DOWN) { 
      startButton.onTouchDown(scaledX, scaledY); 
      scoreButton.onTouchDown(scaledX, scaledY); 
     } 
     if (e.getAction() == MotionEvent.ACTION_UP) { 
      if (startButton.isPressed(scaledX, scaledY)) { 
       startButton.cancel(); 
       setCurrentState(new PlayState()); 
      } else if (scoreButton.isPressed(scaledX, scaledY)) { 
       scoreButton.cancel(); 
       setCurrentState(new ScoreState()); 
      } else { 
       startButton.cancel(); 
       scoreButton.cancel(); 
      } 
     } 
     return true; 
    } 
} 

2. Klasse

package rect.draw.gametest; 

import java.io.IOException; 
import java.io.InputStream; 

import android.graphics.Bitmap; 
import android.graphics.Bitmap.Config; 
import android.graphics.BitmapFactory; 
import android.graphics.BitmapFactory.Options; 
import android.media.AudioManager; 
import android.media.SoundPool; 



public class Assets { 
    private static SoundPool soundPool; 
    public static Bitmap dodgingfire_welcome, block, cloud1, cloud2, duck, grass, jump, 
      run1, run2, run3, run4, run5, scoreDown, score, startDown, start, icLauncher,iceCream1,iceCream2,iceCream3,fire,mountains; 



    // public static Animation runAnim, aba; 
    public static int hitID, onJumpID; 


    public static void load() { 
     icLauncher = loadBitmap("ic_launcher_36",false); 
     dodgingfire_welcome = loadBitmap("dodgingfire_welcome.png", false); 
     block = loadBitmap("block.png", false); 
     cloud1 = loadBitmap("cloud1.png", true); 
     cloud2 = loadBitmap("cloud2.png", true); 
     duck = loadBitmap("duck.png", true); 
     grass = loadBitmap("grass.png", false); 
     jump = loadBitmap("jump.png", true); 
     run1 = loadBitmap("run_anim1.png", true); 
     run2 = loadBitmap("run_anim2.png", true); 
     run3 = loadBitmap("run_anim3.png", true); 
     run4 = loadBitmap("run_anim4.png", true); 
     run5 = loadBitmap("run_anim5.png", true); 
     scoreDown = loadBitmap("score_button_down.png", true); 
     score = loadBitmap("score_button.png", true); 
     startDown = loadBitmap("start_button_down.png", true); 
     start = loadBitmap("start_button.png", true); 
     mountains=loadBitmap("mountains.png",true); 

     iceCream1 = loadBitmap("ice_cream1.png",true); 
     iceCream2=loadBitmap("ice_cream2.png",true); 
     iceCream3=loadBitmap("ice_cream3.png",true); 

     fire=loadBitmap("fire.png",true); 

    //  Frame f1 = new Frame(run1, .1f); 
    //  Frame f2 = new Frame(run2, .1f); 
    //  Frame f3 = new Frame(run3, .1f); 
    // Frame f4 = new Frame(run4, .1f); 
    // Frame f5 = new Frame(run5, .1f); 

    // runAnim = new Animation(f1, f2, f3, f4, f5, f3, f2); 
     hitID = loadSound("hit.wav"); 
     onJumpID = loadSound("onjump.wav"); 
    } 

    private static Bitmap loadBitmap(String filename, boolean transparency) { 
     InputStream inputStream = null; 
     try { 
      inputStream = GameMainActivity.assets.open(filename); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     Options options = new Options(); 
     if (transparency) { 
      options.inPreferredConfig = Config.ARGB_8888; 
     } else { 
      options.inPreferredConfig = Config.RGB_565; 
     } 
     Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, 
       options); 
     return bitmap; 
    } 

    private static int loadSound(String filename) { 
     int soundID = 0; 
     if (soundPool == null) { 
      soundPool = new SoundPool(25, AudioManager.STREAM_MUSIC, 0); 
     } 
     try { 
      soundID = soundPool.load(GameMainActivity.assets.openFd(filename), 
        1); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return soundID; 
    } 

    public static void playSound(int soundID) { 
     soundPool.play(soundID, 1, 1, 1, 0, 1); 
    } 
} 

Antwort

0

das Projekt neu erstellen. Bilder werden beim Erstellen/Speichern nicht bereinigt. Sie müssen den aktuellen Build löschen.