Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PaintObject extends View
- {
- Paint paint;
- public int x;
- public int y;
- public PaintObject(Context context, int dx, int dy)
- {
- super(context);
- paint = new Paint(Paint.ANTI_ALIAS_FLAG);
- paint.setColor(getResources().getColor(R.color.blue));
- this.x = dx;
- this.y = dy;
- paints.add(this);
- }
- public void update()
- {
- x += 5;
- y += 5;
- }
- @Override
- public void onDraw(Canvas canvas)
- {
- if (!paints.contains(this))
- return;
- canvas.drawRect(x, y, x + 20, y + 20, paint);
- invalidate();
- }
- for (PaintObject p : paints)
- {
- if (p.x > screenWidth || p.y > screenHeight)
- {
- paints.remove(p);
- p = null; // compiler says it's never used, but I'm making this for sure so GC will collect it
- }
- else
- p.update();
- }
- layout.addView(new PaintObject (this, 10, 10)); //layout is current layout; xy are randomized in reality
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement