Reputation: 13
I am having issues with by rectangle not stopping (hard coded values due to bugs with grabbing screen height) in addition, when I draw with red paint, I always get a black rectangle no matter what, any ideas?
If you need more code, let me know.
public void draw(Canvas canvas){
Rect rect;
rect = new Rect(x, y, x + SIZE, y + SIZE);
Paint paint = new Paint(Color.rgb(250, 0, 0));
canvas.drawRect(rect, paint);
}
public void update(){
if (this.y < (1920 - SIZE)) {
this.y += 5;
} else if (this.y > 1920){
this.y = 1920 - SIZE;
}
}
Upvotes: 0
Views: 77
Reputation: 5042
The Paint(int)
constructor doesn't take a color value; those are actually flags.
Just use setColor(int)
instead.
If you want it to animate, add a call to invalidate()
to your onDraw()
routine (doesn't really matter where). That way, it keeps getting redrawn, in an endless cycle. Also, call update()
inside onDraw()
as well. Kind of a "poor-man's" animation, but it should get you going.
Upvotes: 1