2013-02-15 6 views
0

내 코드에 대한 질문이 있습니다. 누군가가 화면을 터치 할 때마다 비트 맵을 변경하고 싶습니다. 내 player.java 파일에서디스플레이를 터치 할 때 켜기 비트 맵을 변경하십시오.

protected boolean processTouch(MotionEvent event) { 
    if (event.getAction() == MotionEvent.ACTION_DOWN) { 

     player.setGraphic(BitmapFactory.decodeResource(Game.res, R.drawable.sprite2)); 

    } 
    return true; 
} 

내가 넣어 :

public Sprite(Bitmap bitmap, int x, int y, int width, int height, int fps, int frameCount) 
{ 
    this.bitmap = bitmap; 

} 
public Bitmap getGraphic() 
{ 
    return bitmap; 
} 
private Bitmap bitmap; 

을 그리고 나는 그것을 표시 할 :

public class Player extends Sprite 
{ 
public Player(int x, int y) 
{ 
    super(BitmapFactory.decodeResource(Game.res, R.drawable.sprite1), x-350, y, 50, 17, 5, 2); 

} 
public void update() 
{ 
getGraphic(); 
} 

public Bitmap getGraphic() 
{ 
    return bitmap; 
} 
public void setGraphic(Bitmap bitmap) 
{ 
    this.bitmap = bitmap; 
} 


private Bitmap bitmap;} 

내 Sprite 클래스가 포함

canvas.drawBitmap(s.getGraphic(), s.getSourceRect(), destRect, null); 

그러나 게임을 시작하려고하면 충돌이 발생합니다. 이 문제를 어떻게 해결할 수 있습니까?

편집 :

로그 다음 throwIfRecycled 오류에 대한

02-15 15:29:51.174: I/ActivityManager(18563): Displayed com.example.nic_beta/.Game: +488ms 
02-15 15:29:51.197: W/dalvikvm(29635): threadid=11: thread exiting with uncaught exception (group=0x419cb930) 
02-15 15:29:51.197: E/AndroidRuntime(29635): FATAL EXCEPTION: Thread-23004 
02-15 15:29:51.197: E/AndroidRuntime(29635): java.lang.NullPointerException 
02-15 15:29:51.197: E/AndroidRuntime(29635): at android.graphics.Canvas.throwIfRecycled(Canvas.java:1025) 
02-15 15:29:51.197: E/AndroidRuntime(29635): at android.graphics.Canvas.drawBitmap(Canvas.java:1127) 
02-15 15:29:51.197: E/AndroidRuntime(29635): at com.example.nic_beta.Panel.onDraw(Panel.java:70) 
02-15 15:29:51.197: E/AndroidRuntime(29635): at com.example.nic_beta.RunnerThread.run(Panel.java:187) 
02-15 15:29:51.213: W/ActivityManager(18563): Force finishing activity com.example.nic_beta/.Game 
02-15 15:29:51.260: W/ActivityManager(18563): Force finishing activity com.example.nic_beta/.Menu 
+0

충돌이 발생하면 logcat을 게시하십시오. 또한 모든 터치 다운에서 비트 맵을 디코딩하는 것은 매우 비쌉니다. 처음에 한 번 디코딩 한 다음 터치하여 사전 디코딩 된 비트 맵으로 설정하는 것이 좋습니다. –

답변