Sport Improvement Stack Change is a query and reply website for skilled and impartial recreation builders. It solely takes a minute to enroll.
Anyone can ask a query
Anyone can reply
The very best solutions are voted up and rise to the highest
Requested
Considered
3 instances
I am making a recreation with Javafx. I wish to make my participant node (a fish) eat different nodes (smaller fish), however I do not know methods to use certain and intersect features to do it
public class FishGame extends Utility {
Pane pane;
int x = 0;
Timeline animation;
ImageView participant, iv;
@Override // Override the beginning technique within the Utility class
public void begin(Stage primaryStage) {
pane = new Pane();
Picture background = new Picture("photographs/bg2.jpg");
ImageView background_iv = new ImageView(background);
Picture myfishright = new Picture("photographs/fishIconL15..png");
Picture myfishleft = new Picture("photographs/fishIconL15.png");
participant = new ImageView(myfishleft);
participant.setLayoutX(600);
participant.setLayoutY(300);
pane.getChildren().addAll(background_iv, participant);
getImage(pane);
// Create a scene and place it within the stage
Scene scene = new Scene(pane, 1180, 640);
scene.setOnKeyPressed( e-> {
swap(e.getCode())
{
case RIGHT:
if(participant.getLayoutX() < scene.getWidth() - 90)
{
participant.setImage(myfishright);
participant.setLayoutX(participant.getLayoutX() + 10);
break;
}
else
{
pane.getChildren().take away(participant);
participant.setLayoutX(-50);
participant.setLayoutY(300);
pane.getChildren().add(participant);
break;
}
case LEFT:
if(participant.getLayoutX() > -5)
{
participant.setImage(myfishleft);
participant.setLayoutX(participant.getLayoutX() - 10);
break;
}
else
{
pane.getChildren().take away(participant);
participant.setLayoutX(1150);
participant.setLayoutY(300);
pane.getChildren().add(participant);
break;
}
case UP:
if(participant.getLayoutY() > 0)
{
participant.setLayoutY(participant.getLayoutY() - 10);
break;
}
else
{
break;
}
case DOWN:
if(participant.getLayoutY() < scene.getHeight() - 50)
{
participant.setLayoutY(participant.getLayoutY() + 10);
break;
}
else
{
break;
}
default:
break;
}
});
primaryStage.setTitle("Fish Swallowing"); // Set the stage title
primaryStage.setScene(scene); // Place the scene within the stage
primaryStage.setResizable(false);
primaryStage.present(); // Show the stage
pane.requestFocus();
}
public static void fundamental(String[] args)
{
Utility.launch(args);
}
public void getSlide()
{
Picture[] fish = new Picture[4];
fish[0] = new Picture("https://i.stack.imgur.com/QdkrS.png");
fish[1] = new Picture("https://i.stack.imgur.com/advXv.png");
fish[2] = new Picture("https://i.stack.imgur.com/mXstE.png");
fish[3] = new Picture("https://i.stack.imgur.com/dhSFF.png");
iv = new ImageView(fish[(int)(Math.random() * 4)]);
iv.setLayoutX(1180);
iv.setLayoutY((int)(Math.random() * 640));
TranslateTransition tt = new TranslateTransition();
tt.setDuration(Length.seconds((int)(Math.random() * 5) + 15));
tt.setToX(-1300);
tt.setToY(0);
tt.setNode(iv);
tt.play();
pane.getChildren().add(iv);
}
public void nextSlide()
{
if (x < 3)
{
x += 1;
}
else
x = 0;
getSlide();
}
public void getImage(Pane pane)
{
getSlide();
animation = new Timeline(
new KeyFrame(Length.millis(1000), e -> {
nextSlide();
}));
animation.setCycleCount(Timeline.INDEFINITE);
animation.play();
}
}
$endgroup$
1
You have to log in to reply this query.
default