Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GameView extends View {
- Bitmap ball;
- Random random = new Random();
- private long startTime;
- private int i, j;
- Context mContext;
- public GameView(Context context) {
- super(context);
- mContext = context;
- startTime = System.currentTimeMillis();
- ball = BitmapFactory.decodeResource(getResources(),
- R.drawable.ic_launcher);
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- if (System.currentTimeMillis() - startTime > 2000) {
- startTime = System.currentTimeMillis();
- i = random.nextInt(getWidth());
- j = random.nextInt(getHeight() / 2);
- Ball b = new Ball(mContext, i, j);
- canvas.drawBitmap(b.getBall(), i, j, null);
- }
- invalidate();
- }
- public class Ball {
- private Bitmap ball;
- Context context;
- Resources res;
- Canvas canvas;
- private int i,j;
- public Ball(Context mContext, int i, int j) {
- context = mContext;
- this.i = i;
- this.j = j;
- ball = BitmapFactory.decodeResource(context.getResources(),
- R.drawable.ic_launcher);
- }
- public void setBall(Bitmap ball) {
- this.ball = ball;
- }
- public Bitmap getBall() {
- return ball;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement