-
Notifications
You must be signed in to change notification settings - Fork 0
Eclipse Project Configuration
Most of this information is no longer accurate with respect to Ridhvl2's master branch. A new setup guide will be created when time allows. In the meantime (if you absolutely must use the old configuration) you can switch to the legacy-lwjgl2 branch.
The following page assumes Ridhvl2 has already been cloned and imported as a workspace project. Learn how to do that on this page.
This section explains how to set up an Eclipse project that implements Ridhvl2 functionality. This procedure must be repeated once for every new project.
It's important to check for new Ridhvl2 updates before starting a project.
I. Right click on the Ridhvl2 project in Project Explorer.
II. Choose Team > Pull. Make sure the Reference text field is set to master and click Finish.
III. Click OK in the dialog that opens. Your local version of Ridhvl2 is now up to date.
I. Navigate in the top toolbar File > New > Project.
II. In the New Project dialog select Java > Java Project from the Wizards list.
III. Enter a name for your project and click Finish.
At this point we've created a standard Java project. Now we need to add Ridhvl2 to the project's build path so we can use the features of Ridhvl2.
IV. Right click on the new project in Project Explorer.
V. Choose Build Path > Configure Build Path....
VI. In the Java Build Path section, select the Projects tab at the top.
VII. Click Add.... Select Ridhvl2 and click OK.
VIII. Ensure Ridhvl2 now appears in the Projectssection of the Java Build Path page. Click Apply and then OK.
Congratulations! Your project is now set up. You're ready to begin writing code!
Ridhvl2 is accessed through a single abstract class. You'll need to extend that class, override two timing methods and call the parent class's constructor. Everything else is handled behind the scenes by Ridhvl2.
I. Create a new class by right clicking the project and selecting New > Class. Enter a name for your class and click Finish.
You'll need to select a HvlTemplate to manage your program. In this example we'll use HvlTemplateI ("I" stands for "integrated") because it includes everything necessary to create a game.
II. Add the extends declaration for HvlTemplateI to the class header. Your code should look similar to the following (excluding imports):
public class MyMainClass extends HvlTemplateI{
}III. Create a constructor override. We don't need any arguments for this constructor override. You'll need to call the constructor of the parent class with the super call. Choose the parent class's constructor with only a single HvlDisplay argument, nothing else. You'll need to feed this super call a new instance of HvlDisplay. For this example we'll use a HvlDisplayWindowed. Let's supply reasonable arguments for HvlDisplayWindowed that describe the display for our program to use (in this case a 144Hz, 1280x720, non-resizable window titled "My Ridhvl Game Window").
Your code should look similar to the following:
public class MyMainClass extends HvlTemplateI{
public MyMainClass() {
super(new HvlDisplayWindowed(144, 1280, 720, "My Ridhvl Game Window", false));
}
}More on HvlDisplay
For this example we chose to use a instance of HvlDisplayWindowed. This HvlDisplay creates a standard, draggable window on which graphics can be drawn. The arguments for HvlDisplayWindowed's constructor are as follows:
HvlDisplayWindowed([max refresh rate], [window width], [window height], [window title], [is window resizable])
There are many options when it comes to choosing an HvlDisplay implementation. HvlDisplayWindowed also supports undecorated windows, and HvlDisplayFullscreenAuto automatically selects an appropriate fullscreen resolution supported by the user's system. In Eclipse, type new HvlDisplay and then press Ctrl+Space to see all available options.
IV. Insert the necessary method overrides. This is best done by hovering over the error on the class name and selecting Add unimplemented methods. This will create the void initialize() and void update(float delta) methods.
Example Code Snippet
Your code should look similar to the following:
public class MyMainClass extends HvlTemplateI{
public MyMainClass() {
super(new HvlDisplayWindowed(144, 1280, 720, "My Ridhvl Game Window", false));
}
@Override
public void initialize() {
}
@Override
public void update(float delta) {
}
}
V. Create a main method that instantiates your new class. All you need to do is call the constructor you created, i.e. new MyMainClass();.
Example Code Snippet
Your code should look similar to the following:
public class MyMainClass extends HvlTemplateI{
public static void main(String[] args) {
new MyMainClass();
}
public MyMainClass() {
super(new HvlDisplayWindowed(144, 1280, 720, "My Ridhvl Game Window", false));
}
@Override
public void initialize() {
}
@Override
public void update(float delta) {
}
}
Congratulations! You've created a functioning Ridhvl2 program. You're ready to start drawing graphics!
With HvlTemplateI, Ridhvl2 handles everything behind the scenes (creating the window, prepping the graphics engine, timing program updates, etc.). void initialize() and void update(float delta) are called automatically from within the template. You don't need to call these methods.
initialize is run once on program startup. This method will run when the template constructor has been called, before the first update method is run.
This method should be used to load textures, sounds and other resources. This method should also be used to perform variable initialization across the entire program.
This will effectively function as the loading screen portion of your game, and all cpu-intensive operations should be placed here.
update is run repeatedly for the duration of the program lifespan. This method runs for the first time after initialize is run, and for the last time after HvlTemplate.setExiting() is called. The rate at which this method runs is specified by the program's HvlDisplay. The float delta argument is the number of seconds since the last update execution.
This method should be used to draw graphics, play sounds and check for user inputs. This method should also be used to update all game logic and perform all program runtime actions.
This will effectively function as the core update loop of your game. This method should be as lightweight as possible to increase program performance.