Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public class GameView extends View {
  2. Bitmap ball;
  3. Random random = new Random();
  4. private long startTime;
  5. private int i, j;
  6. Context mContext;
  7.  
  8. public GameView(Context context) {
  9. super(context);
  10. mContext = context;
  11. startTime = System.currentTimeMillis();
  12. ball = BitmapFactory.decodeResource(getResources(),
  13. R.drawable.ic_launcher);
  14. }
  15.  
  16. @Override
  17. protected void onDraw(Canvas canvas) {
  18. super.onDraw(canvas);
  19.  
  20. if (System.currentTimeMillis() - startTime > 2000) {
  21. startTime = System.currentTimeMillis();
  22. i = random.nextInt(getWidth());
  23. j = random.nextInt(getHeight() / 2);
  24. Ball b = new Ball(mContext, i, j);
  25. canvas.drawBitmap(b.getBall(), i, j, null);
  26.  
  27.  
  28. }
  29.  
  30. invalidate();
  31. }
  32.  
  33. public class Ball {
  34. private Bitmap ball;
  35. Context context;
  36. Resources res;
  37. Canvas canvas;
  38. private int i,j;
  39.  
  40. public Ball(Context mContext, int i, int j) {
  41. context = mContext;
  42. this.i = i;
  43. this.j = j;
  44. ball = BitmapFactory.decodeResource(context.getResources(),
  45. R.drawable.ic_launcher);
  46.  
  47. }
  48.  
  49. public void setBall(Bitmap ball) {
  50. this.ball = ball;
  51. }
  52. public Bitmap getBall() {
  53. return ball;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement