Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 2 KB

utility.md

File metadata and controls

42 lines (32 loc) · 2 KB

#Utility file

This file contains several classes and methods that may be of use.

Application:
static void launch(String[] args) Launches the game. Call this method in the main method of your main class.
abstract void start(Stage stage) Called by launch. Initialize variables and set up your game in this method.

Stage:
void setTitle(String title) This is the title that appears in the bar at the top of the window.
void setScene(Scene scene)
void setHeight(double height)
void setWidth(double width)
void setResizable(boolean resizable)
void show() Call this after setting up the stage to display it.

Canvas:
void Canvas(double width, double height)
GraphicsContext getGraphicsContext2D()

GraphicsContext:
void drawImage(Image image, double x, double y) Draws an Image with its top left corner at the specified coordinates.
void setFill(Color color) Applies to all subsequent fills.
void fillText(String text, double x, double y) Draw text with the specified fill color at the specified coordinates.
void clearRect(double x, double y, double width, double y) Erases the specified rectangle.
void drawRect(double x, double y, double width, double height) Draws a rectangle with the current fill color at the specified coordinates

Image:
void Image(String url) The URL for an image in the src folder named spike.png would be "/spike.png". Note that loading an image from a url takes a lot of time, so if you are drawing the same image many times in a frame, you want to load it only once and reuse the Image object to prevent the game from lagging.

Group:
void Group(Node... nodes)

Scene:
void Scene(Group group)
void setOnKeyPressed(EventHandler)

AnimationTimer:
void handle(long now)

EventHandler<?> (interface):
void handle(KeyEvent event)