2

The issue I'm having is this, I am currently messing around with JavaFX and graphics in general with Java, I still consider myself an amateur, and I'm making a small pixel game just to improve my knowledge and experience with graphics. I would like to alternate between a few images just to simulate a "bounce" to the pixel character i have created, just to add a little bit of liveliness to the program, but i am having a lot of trouble figuring out how to do this, i have spent quite some time trying to find a solution to my specific problem to no avail. I would appreciate any help you could give, and if you feel like it, tips on improving my code as well as mistakes i am making. Thank you for your time. Sorry if i pasted the code incorrectly, first timer.

package view;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;

// import JavaFX classes: Application, Stage, Scene, HBox, and Label.

public class JavaFXTesting extends Application {

    Stage window;
    Scene sceneIntro, sceneFBM;

    public static void main(String[] args) {

        // Launch the application.
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        window = primaryStage;

        int loop = 0;

        primaryStage.getIcons().add(new Image("file:PixelChar.png"));
        Image pixelScene1 = new Image("file:PixelScene.png");
        Image pixelScene2 = new Image("file:PixelScene2.png");
        ImageView pixScene1 = new ImageView(pixelScene1);
        ImageView pixScene2 = new ImageView(pixelScene2);
        pixScene1.setPreserveRatio(true);
        pixScene2.setPreserveRatio(true);

        pixScene1.setFitWidth(400);
        pixScene1.setFitHeight(350);
        pixScene2.setFitWidth(400);
        pixScene2.setFitHeight(350);

        Label promptWelcome = new Label(":Welcome To Meme Adventure!:");
        Label promptIntro =
                new Label("You are currently playing the pre pre pre pre Alpha version\n"
                        +
                        " of Meme Adventrue, which involves you memeing on various enemies.\nEnjoy!");
        Label promptAction =
                new Label("Oh no! a wild FeelsBadMan as appeared!\n Quickly! Attack it.");

        promptWelcome.setFont(new Font("Impact", 20));
        promptIntro.setTextAlignment(TextAlignment.CENTER);
        promptAction.setTextAlignment(TextAlignment.CENTER);
        promptIntro.setFont(new Font("Franklin Gothic Demi", 13));
        promptAction.setFont(new Font("Franklin Gothic Demi", 13));
        promptIntro.setWrapText(true);
        promptAction.setWrapText(true);

        Button switchButton = new Button("Meme!");
        switchButton.setOnAction(e -> window.setScene(sceneFBM));
        Button testButton = new Button("Attack!");
        testButton.setOnAction(e -> window.setScene(sceneIntro));
        Button exitOption1 = new Button("Exit Program");
        exitOption1.setOnAction(e -> window.close());
        Button exitOption2 = new Button("Exit Program");
        exitOption2.setOnAction(e -> window.close());

        HBox buttonLayout2 = new HBox(10, exitOption1, switchButton);
        VBox intro = new VBox(10, pixScene1, promptWelcome, promptIntro, buttonLayout2);

        HBox buttonLayout1 = new HBox(10, exitOption2, testButton);
        VBox intro2 = new VBox(10, pixScene2, promptAction, buttonLayout1);

        intro.setAlignment(Pos.CENTER);
        intro.setPadding(new Insets(10));
        intro2.setAlignment(Pos.CENTER);
        buttonLayout1.setAlignment(Pos.CENTER);
        buttonLayout2.setAlignment(Pos.CENTER);
        intro2.setPadding(new Insets(10));

        sceneIntro = new Scene(intro);
        sceneFBM = new Scene(intro2);

        window.setScene(sceneIntro);
        window.setTitle("Meme Adventures");
        window.show();
    }
}
Vanguard
  • 1,336
  • 1
  • 15
  • 30

1 Answers1

0

A likely error could be that when you are constructing your images, you put file: before your file name. This could be proved by adding this line of code after you create your images.

System.out.println(pixelScene1.isError());

This returns true even if the file exists. try removing where you see file on line 37, 39, and 39.

StackDoubleFlow
  • 323
  • 4
  • 12