-1
我正在嘗試開發該項目,而目前我正在做簡單的任務。我想移動一些我在屏幕上繪製的繪圖。在Android中移動的形狀
我的問題是,我畫了一些Rect對象和路徑,當我執行它時,只是矩形正在移動。
當我移動矩形時,在每次執行時,繪製的矩形被刪除,並且「新的」被繪製,但它不會在路徑中發生。
對不起,我可憐的解釋,這裏是一些代碼:
public void run(){
preparePaint();
while(CanDraw){
if (!surfaceHolder.getSurface().isValid()){
continue;
}
canvas = surfaceHolder.lockCanvas();
if (ini == true){ SenStart(canvas); ini = false;}
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
rectangle0.set(sensor0.left, sensor0.top, sensor0.right, sensor0.bottom);
motion();
canvas.drawRect(rectangle0, red_fill);
canvas.drawPath(wallpath, red_fill);
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
這是圖紙的初始化:
protected void SenStart(Canvas canvas){
robot.x1 = getWidth() /2 - 100;
robot.y1 = getHeight()/2 + 40;
robot.x2 = getWidth() /2 - 100;
robot.y2 = getHeight()/2 -80;
robot.x3 = getWidth()/2;
robot.y3 = getHeight()/2 -140;
robot.x4 = getWidth() /2 + 100;
robot.y4 = getHeight()/2 -80;
robot.x5 = getWidth()/2 + 100;
robot.y5 = getHeight()/2 + 40;
wallpath.moveTo(robot.x1, robot.y1); // used for first point
wallpath.lineTo(robot.x2, robot.y2);
wallpath.lineTo(robot.x3, robot.y3);
wallpath.lineTo(robot.x4, robot.y4);
wallpath.lineTo(robot.x5, robot.y5);
wallpath.lineTo(robot.x1, robot.y1); // used for first point
sensor0.left = getWidth() /2 - 150;
sensor0.bottom = getHeight()/2 - 20;
sensor0.right = getWidth()/2 - 130;
sensor0.top = getHeight()/2;
}
}
這裏就是我想補充運動中的對象:
private void motion(){
robot.y1 = robot.y1 -1;
robot.y2 = robot.y2 -1;
robot.y3 = robot.y3 -1;
robot.y4 = robot.y4 -1;
robot.y5 = robot.y5 -1;
wallpath.moveTo(robot.x1, robot.y1); // used for first point
wallpath.lineTo(robot.x2, robot.y2);
wallpath.lineTo(robot.x3, robot.y3);
wallpath.lineTo(robot.x4, robot.y4);
wallpath.lineTo(robot.x5, robot.y5);
wallpath.lineTo(robot.x1, robot.y1); // used for first point
sensor0.top = sensor0.top -1;
sensor0.bottom = sensor0.bottom -1;
}