我试着解决我失踪的问题。我绘制一个画布的矩形它工作正常,但如果我将坐标从这个矩形更改为底部,它的消失器将从屏幕上消失。
这些代码显示我的矩形:
public class GameView extends View {
private Paint paint;
private Rect recco;
private GameObject ball;
public GameView(Context context) {
super(context);
initGame(context);
}
public GameView(Context context, AttributeSet attrs) {
super(context, attrs);
initGame(context);
}
public GameView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initGame(context);
}
public void initGame(Context context){
paint = new Paint();
paint.setColor(Color.BLACK);
paint.setStrokeWidth(3);
//ball = new GameObject(context);
recco = new Rect(0,100,200,200); // top left coordinates
//ball.setSprite(R.drawable.menu_background);
}
@Override
public void onDraw(Canvas canvas){
canvas.drawRect(recco, paint);
// ball.render(canvas);
}
}
现在我将坐标更改为X = 0而Y = 400则会消失
public void initGame(Context context){
paint = new Paint();
paint.setColor(Color.BLACK);
paint.setStrokeWidth(3);
//ball = new GameObject(context);
recco = new Rect(0,400,200,200);
//ball.setSprite(R.drawable.menu_background);
}