Repository navigation
ExampleApplication
da772 edited this page Feb 26, 2020
·
6 revisions
Creating an application is as simple as creating a class that extends the Application class. The constructor must call super to ensure the window is created correctly.
import engine.Application;
import engine.Events.Event;
public class TestingApp extends Application {
public TestingApp() {
// Call super - Set window Title to "Testing" set width to 1280 set height to 720
super("Testing", 1280, 720);
}
// Initializing app
@Override
protected void OnInit() {
System.out.println(title+" Init!");
}
// Called every frame
@Override
protected void OnUpdate(float deltaTime) {
}
// Camera OnEvent
protected void OnEvent(Event event) {
};
//Key Event
@Override
protected boolean KeyEvent(Events.KeyEvent e) {
return false;
}
// Scroll Event
@Override
protected boolean MouseScrolledEvent(Events.MouseScrolledEvent e) {
return false;
}
// Called on application end
@Override
protected void OnShutdown() {
System.out.println(title+ " Shutdown!");
}
}Applications by default have the window events routed to their OnEvent function. The parameter passed, Event, can be casted to many different event types which gives full control of all the events received.
// On Event
protected void OnEvent(Event event) {
cam.OnEvent(event); // pass the events to the camera
if (event instanceof Events.KeyPressedEvent) {
Events.KeyPressedEvent keyEvent = (Events.KeyPressedEvent) event; // Cast the event
if (keyEvent.GetKeyCode() == KeyCodes.Key_F) { // Check if the key pressed is a F
System.out.println("We pressed the letter F!");
}
}
};