Hi all, My purpose is very simple : each 1second, I want to redraw an object on different place on background. I do not know where my error on this code below. Hope that you can show me or give me an advice to fix this problem
Here is my code ********************************************************************************************************************** public class My_View extends View{ private Bitmap mBackground_img; private Drawable mMoveObject; private int mObjectw,mObjecth; private int Dx,Dy; private Handler myHandler = new Handler(); private long lasttime; public My_View(Context context,AttributeSet ats,int ds) { super(context,ats,ds); init(context); } public My_View(Context context,AttributeSet ats) { super(context,ats); init(context); } public My_View(Context context) { super(context); init(context); } public void change() { invalidate(); } private void init(Context context) { Resources res = context.getResources(); mMoveObject = res.getDrawable (R.drawable.lander_firing); mBackground_img = BitmapFactory.decodeResource(res, R.drawable.my_pic); mObjectw = mMoveObject.getIntrinsicWidth(); mObjecth = mMoveObject.getIntrinsicHeight(); Dx = Dy = 0; lasttime = System.currentTimeMillis() + 1000; Thread mthread = new Thread(null,doBackground,"Background"); mthread.start(); } private Runnable doBackground = new Runnable() { public void run() { long now = System.currentTimeMillis(); if(lasttime < now ) { Dx = Dx + 10; Dy = Dy + 10; lasttime = now + 1000; myHandler.post(change_view); } } }; private Runnable change_view = new Runnable() { public void run() { change(); } }; @Override public void onDraw(Canvas canvas) { canvas.drawBitmap(mBackground_img,0 ,0 , null); mMoveObject.setBounds(Dx, Dy, Dx+mObjectw, Dy+mObjecth); mMoveObject.draw(canvas); } } ********************************************************************************************************************** Hope to see your reply soon, Thanks in advance, NPAK --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---