这是我的GamePanel类连接到它的超类startUp.java(未列出startUp类)。
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import static javafx.scene.paint.Color.LIGHTGREEN;
import static javafx.scene.paint.Color.RED;
public class GamePanel extends Stage {
private boolean axisDown, axisUp, yawLeft, yawRight, throttleUp, throttleDown;
private double xPosition = 0, yPosition = 0, zPosition = 0;
private int resolutionX = 0, resolutionY = 0;
private int speedValue = 0;
private int throttleValue = 10;//Make sure that throttle doesnt go below 10%.. will add stall feature that will allow you to go to 0% throttle in future version
private int altitudeValue = 5000; //crashes will occur when you touch an object such as a mountain or if altitudeValue is <= 0
//angle increment variables
private int yAngleIncrementInitializer = 180;
private int xAngleIncrementInitializer = (1100/2)-150;
private int incrementLength = 300;
private int incrementValue = 5;//CORRECT LATER
public GamePanel()
{
super();
startGame(this);
}
public void startGame(Stage GamePanel)
{
angleIncrement[] angleIncrementsArray = new angleIncrement[71];
for(int incrementNamePlace = 0; incrementNamePlace < 71; incrementNamePlace ++)
{
angleIncrementsArray[incrementNamePlace] = new angleIncrement(incrementLength, incrementValue, xAngleIncrementInitializer, yAngleIncrementInitializer);
angleIncrementsArray[incrementNamePlace].displayIncrement();
yAngleIncrementInitializer+=5;
}
}
现在这是我的angleIncrement类,它被实例化为72行。
import javafx.scene.shape.Line;
import javafx.stage.Stage;
public class angleIncrement
{
public int length;
public int incrementValue;
public int xPlacement;
public int yPlacement;
public angleIncrement(int incrementLength, int incrementValue, int xAngleIncrementInitializer, int yAngleIncrementInitializer)
{
super();
//displayIncrement(this);
length = incrementLength;
this.incrementValue = incrementValue;
xPlacement = xAngleIncrementInitializer;
yPlacement = yAngleIncrementInitializer;
}
public void displayIncrement()
{
Line newIncrement = new Line();
newIncrement.setStartY(yPlacement);
newIncrement.setEndX(newIncrement.getStartX()+300);
newIncrement.setEndY(newIncrement.getStartY());
}
}
所以我希望它能够打印出y值相差5个像素的线条。为了实现这个目的,我认为问题在于我无法在我的angleIncrement对象中打印这些行,因为对象“Line”是javaFX库的一个成员,我无法在我的角度增量对象中获取而没有创建一个全新的阶段。
如果有人可以提供帮助,我将非常感激。