我编写了一个简单的 Java 游戏,其中屏幕上有两个矩形,一个矩形移动,另一个保持静止,移动的矩形随着键盘箭头输入移动,可以向上、向下、向左或向右移动。我遇到的问题是在屏幕上绘制矩形,我的变量设置如下所示:
float buckyPositionX = 0;
float buckyPositionY = 0;
float shiftX = buckyPositionX + 320;//keeps user in the middle of the screem
float shiftY = buckyPositionY + 160;//the numbers are half of the screen size
//my two rectangles are shown under here
Float rectOne = new Rectangle2D.Float(shiftX, shiftY,90,90);
Float rectTwo = new Rectangle2D.Float(500 + buckyPositionX, 330 + buckyPositionY, 210, 150);
在我的渲染方法(它包含我想在屏幕上绘制的所有东西)下,我告诉 Java 绘制我的两个矩形:
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
//draws the two rectangles on the screen
g.fillRect(rectOne.getX(), rectOne.getY(), rectOne.getWidth(), rectOne.getHeight());
g.fillRect(rectTwo.getX(), rectTwo.getY(), rectTwo.getWidth(), rectTwo.getHeight());
}
但是我在fillRect下收到以下错误:
This method fillRect(float,float,float,float) in the type graphics is
not applicable for the arguments (double,double,double,double)
这让我感到困惑,因为据我了解,它是说 fillRect 中提供的信息应该是浮点数,所以为什么它一直给我这个错误?