public class GamePlay extends SurfaceView implements View.OnTouchListener{
float x=10,y=10;
float touched_x=0,touched_y=0;
Bitmap bitmap;
SurfaceHolder holder;
MyThread thread;
boolean touched=false;
public GamePlay(Context context) {
super(context);
holder=getHolder();
thread=new MyThread();
bitmap= BitmapFactory.decodeResource(getResources(),R.mipmap.ball);
holder.addCallback(new SurfaceHolder.Callback() {
@SuppressLint("WrongCall")
@Override
public void surfaceCreated(SurfaceHolder holder) {
thread.setRunning(true);
thread.start();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
});
}
@Override
public boolean onTouch(View v, MotionEvent event) {
touched_x = event.getX();
touched_y = event.getY();
int action = event.getAction();
switch(action){
case MotionEvent.ACTION_DOWN:
touched = true;
break;
case MotionEvent.ACTION_MOVE:
touched = true;
break;
case MotionEvent.ACTION_UP:
touched = false;
break;
case MotionEvent.ACTION_CANCEL:
touched = false;
break;
case MotionEvent.ACTION_OUTSIDE:
touched = false;
break;
default:
}
return true;
}
class MyThread extends Thread{
boolean running=false;
public void setRunning(boolean running){
this.running=running;
}
@Override
public void run() {
Canvas canvas=null;
while (running){
try{
canvas=holder.lockCanvas();
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(bitmap,x,y,null);
if(touched){
canvas.drawBitmap(bitmap,touched_x,touched_y,null);
}
}finally {
if(canvas!=null){
holder.unlockCanvasAndPost(canvas);
}
}
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview I/dalvikvm: Could not find method android.view.View.getTranslationZ, referenced from method com.example.robiul.surfaceview.GamePlay.access$super 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview W/dalvikvm: VFY: unable to resolve virtual method 15283: Landroid/view/View;.getTranslationZ ()F 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview D/dalvikvm: VFY: replacing opcode 0x6f at 0x13c2 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview I/dalvikvm: Could not find method android.view.View.getBackgroundTintList, referenced from method com.example.robiul.surfaceview.GamePlay.access$super 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview W/dalvikvm: VFY: unable to resolve virtual method 15170: Landroid/view/View;.getBackgroundTintList ()Landroid/content/res/ColorStateList; 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview D/dalvikvm: VFY: replacing opcode 0x6f at 0x1417 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview I/dalvikvm: Could not find method android.view.View.setBackgroundTintList, referenced from method com.example.robiul.surfaceview.GamePlay.access$super 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview W/dalvikvm: VFY: unable to resolve virtual method 15456: Landroid/view/View;.setBackgroundTintList (Landroid/content/res/ColorStateList;)V 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview D/dalvikvm: VFY: replacing opcode 0x6f at 0x14e5 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview I/dalvikvm: Could not find method android.view.View.invalidateOutline, referenced from method com.example.robiul.surfaceview.GamePlay.access$super 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview W/dalvikvm: VFY: unable to resolve virtual method 15310: Landroid/view/View;.invalidateOutline ()V 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview D/dalvikvm: VFY: replacing opcode 0x6f at 0x1631 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview I/dalvikvm: Could not find method android.view.View.getForeground, referenced from method com.example.robiul.surfaceview.GamePlay.access$super 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview W/dalvikvm: VFY: unable to resolve virtual method 15196: Landroid/view/View;.getForeground ()Landroid/graphics/drawable/Drawable; 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview D/dalvikvm: VFY: replacing opcode 0x6f at 0x16a5 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview I/dalvikvm: Could not find method android.view.View.setContextClickable, referenced from method com.example.robiul.surfaceview.GamePlay.access$super 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview W/dalvikvm: VFY: unable to resolve virtual method 15464: Landroid/view/View;.setContextClickable (Z)V 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview D/dalvikvm: VFY: replacing opcode 0x6f at 0x16f8 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview I/dalvikvm: Could not find method android.view.View.getOutlineProvider, referenced from method com.example.robiul.surfaceview.GamePlay.access$super 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview W/dalvikvm: VFY: unable to resolve virtual method 15235: Landroid/view/View;.getOutlineProvider ()Landroid/view/ViewOutlineProvider; 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview D/dalvikvm: VFY: replacing opcode 0x6f at 0x1704 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview I/dalvikvm: Could not find method android.view.View.requestApplyInsets, referenced from method com.example.robiul.surfaceview.GamePlay.access$super 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview W/dalvikvm: VFY: unable to resolve virtual method 15426: Landroid/view/View;.requestApplyInsets ()V 06-15 03:11:01.972 11268-11268/com.example.robiul.surfaceview D/dalvikvm: VFY: replacing opcode 0x6f at 0x1720 06-15 03:11:01.982 11268-11268/com.example.robiul.surfaceview I/dalvikvm: Could not find method android.view.View.getZ, referenced from method com.example.robiul.surfaceview.GamePlay.access$super 06-15 03:11:01.982 11268-11268/com.example.robiul.surfaceview W/dalvikvm: VFY: unable to resolve virtual method 15298: Landroid/view/View;.getZ ()F 06-15 03:11:01.982 11268-11268/com.example.robiul.surfaceview D/dalvikvm: VFY: replacing opcode 0x6f at 0x1878 06-15 03:11:01.982 11268-11268/com.example.robiul.surfaceview I/dalvikvm: Could not find method android.view.View.getForegroundTintMode, referenced from method com.example.robiul.surfaceview.GamePlay.access$super 06-15 03:11:01.982 11268-11268/com.example.robiul.surfaceview W/dalvikvm: VFY: unable to resolve virtual method 15199: Landroid/view/View;.getForegroundTintMode ()Landroid/graphics/PorterDuff$Mode; 06-15 03:11:01.982 11268-11268/com.example.robiul.surfaceview D/dalvikvm: VFY: replacing opcode 0x6f at 0x19db 06-15 03:11:02.072 11268-11268/com.example.robiul.surfaceview D/OpenGLRenderer: Enabling debug mode 0 06-15 03:11:02.132 11268-11268/com.example.robiul.surfaceview W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection 06-15 03:11:02.132 11268-11268/com.example.robiul.surfaceview I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@41f1bb28 time:238361244 06-15 03:11:04.224 11268-11268/com.example.robiul.surfaceview I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@41f1bb28 time:238363344 06-15 03:11:09.760 11268-11295/com.example.robiul.surfaceview W/dalvikvm: threadid=12: thread exiting with uncaught exception (group=0x4170fbc0) 06-15 03:11:09.770 11268-11295/com.example.robiul.surfaceview E/AndroidRuntime: FATAL EXCEPTION: Thread-7935 Process: com.example.robiul.surfaceview, PID: 11268 java.lang.NullPointerException at com.example.robiul.surfaceview.GamePlay$MyThread.run(GamePlay.java:88) 06-15 03:11:11.902 11268-11295/com.example.robiul.surfaceview I/Process: Sending signal. PID: 11268 SIG: 9
Aucun commentaire:
Enregistrer un commentaire