0
Point p1 = new Point(100, 100);
Point p2 = new Point(300, 100);
Point p3 = new Point(110, 100);
int x3 = 310;
Point p4 = new Point(100, 100);
static JFrame start = new JFrame("Start");

if(p3.x >= start.getWidth()-90)
{
    p3.x = (int) (p1.getX()+10);
    p3.setLocation(p3.x, p3.y);
    repaint();
}

if(key == KeyEvent.VK_S && !paused)
{
    p1.y++;
    p4.y++;
    p1.setLocation(p1.x, p1.y);
    test1.setBounds(new Rectangle(p1, new Dimension(64, 64)));
    repaint();
    sound.soundPlay(3);
}

在此,点 p3 的 x 值应该与 p1.getX()+10 的值相同。该值更改为 100+10,但我在第二个块中将 100 更改为不同的值。如何更新第一个块中的 p1 以匹配第二个块中的 p1?

4

1 回答 1

0

我找到了我的问题的答案。这是我的新代码:

Point p1 = new Point(100, 100);
Point p2 = new Point(300, 100);
Point p3 = new Point(110, 100);
Point p5 = new Point(310, 100);
Point p4 = new Point(90, 100);
static JFrame start = new JFrame("Start");

if(p3.x >= start.getWidth()-90)
{
    p3.x = start.getWidth()-70;
    p3.x = (int) (p1.getX()+10);
    p3.setLocation(p3.x, p3.y);
}

if(key == KeyEvent.VK_S && !paintingFBR && !paused)
{
    p1.y++;
    p3.y++;
    test1.setLocation(p1);
    test3.setLocation(p3);
}
于 2012-09-08T16:44:28.153 回答