我有一个圆圈类,它有一个绘图功能,,, 我有一个视图类,它创建3个不同颜色的3个圆圈, 我在屏幕上成功绘制圆圈,左边1个,中间1个,右边1个...... 圆的高度几乎相同,高度不同......
O
O
O
想象一下3个球,但高度较小(当球向左或向右移动时)。 现在我的问题是,我正试图将球移到右上角,左侧角落,同时将左下角的球更多地移到右下角,我看到他们两个都出现在上方中间的球,但我想要的是顶球出现在中间球后面,最后一个球出现在中间球的上方,就像现在一样,我怎么能做到这一点?
EDIT :::
public class picture {
private Bitmap bitmapPicture; // the actual bitmap
private int x; // the X coordinate
private int y; // the Y coordinate
...
public void draw(Canvas canvas,Paint paint) {
canvas.drawBitmap(bitmapPicture, x , y , paint);
}
some functions to move it to the right,, and left...
.....
}
我的View类:
public class GamePanel extends View implements Runnable{
private Picture[] picture;
.....
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
for(int i=0;i<cupsNumber;i++){
cup[i].draw(canvas,paint);
}
invalidate();
}
}
现在在我的视图类中,我激活了将i = 0上的图像向右移动更多的函数,以及i = 2到左边的图片,(i =右上角的0,i = 2,左下角)现在他们都与中间的图片相交但不完全隐藏它,所以在中间宽度,我可以看到所有的图片,现在我的问题是,我看到球向左移动在中间球的顶部和在中间球顶部向右移动的球(有时是随机的,就像它们都在中间的后面等) 我想要的是,球在中间位于球的中间位置,球在中间位于球的上方,我怎么能这样做?
答案 0 :(得分:0)
您可能需要自己管理位图。
用于绘制位图的View
类实际上应该是View
的子类,它会覆盖onDraw()
。例如:
public class myCircleDrawer extends View {
Bitmap circle1, circle2, circle3;
@Override
public void onDraw(canvas c) {
c.drawBitmap(bitmap1);
}
}
尝试阅读Canvas
文档,以了解用于更改位图的(x,y)坐标的方法,以便移动它们
编辑:
好的,现在我明白了,如果您要做的是游戏,我建议您查看SurfaceView
和SurfaceView.Renderer
。这背后的原因是您需要自己管理对draw()
函数的调用,而不是覆盖onDraw()
;更新实体属性后所有这些。