Red Utils (Remastered) is a library made by me (RedSponge) in Java, which is designed to make creating 2d games a very easy process! As of now the library supports:
- Input listeners for both mouse and keyboard
- Audio (currently supports ogg)
- Efficient texture loading, and various rendering methods for it
- Multithreading
First thing to do is download the RedUtilsRemastered jar file (check releases for download or just go to the builds folder)
and add it as a library/dependency to your project.
After you did that, your main class needs to extend GraphicsApp
public class Example extends GraphicsAppYou will need to implement three methods: init, tick and render as well as a constructor:
GraphicsApp(String title, int screen_width, int screen_height, int ticksPerSecond, int framesPerSecond)A more complicated version of the constructor contains also boolean printTPS, boolean printFPS, int numThreads
IMPORTANT: The method start() must be called at the end of the constructor or the app won't run
In the end, you should have a class that looks like this:
public class ExampleApp extends GraphicsApp {
public Example() {
super("An example app", 640, 480, 60, 60)
start()
}
@Override
public void init() {
}
@Override
public void tick() {
}
@Override
public void render() {
}
}In your main method, just create a new instance of the main class.
public static void main(String[] args) {
new Example();
}To create an instance of the class all you need to do is add a public static field of your class with the @Instance annotation above it.
@Instance
public static ExampleApp INSTANCE;Its value will be injected using reflection during the initiation sequence.
Every GraphicsApp instance has a protected InputManager field that is registered to its frame, the input manager has the following methods:
-
registerToDisplay(GraphicsDisplay display)- Adds the mouse and key listeners to the display, automatically done by GraphicsApp -
isKeyHeld(int key)- returns true as long as the key is pressed\held -
isKeyJustPressed(int key)- returns true for the first tick the key is held -
isKeyReleased(int key)- returns true as long as the key is not pressed\held -
isKeyJustReleased(int key)- returns true for the first tick after the key has been released -
isMouseButtonHeld(int button)- returns true as long as the button is pressed\held -
isMouseButtonJustPressed(int button)- returns true for the first tick the button is held -
isMouseButtonReleased(int button)- returns true as long as the button is not pressed\held -
isMouseButtonJustReleased(int button)returns true for the first tick after the button has been released -
getMouseX()- returns current mouse X position -
getMouseY()- returns current mouse Y position
To get the inputManager outside of the main class, use the GraphicsApp.getInputManager() on an instance of your class
To render, use the Graphics2D g field which is a protected field in the GraphicsApp class, and can be used freely:
@Override
public void render() {
g.drawRect(100, 100, 200, 200);
g.fill(aRectangleIDeclaredEarlier);
}Using the Texture.load(String path) method you can load internal textures (from a res folder for example). if you're using png, you can type the name without the ".png" extension, otherwise, add the extension in the path.
- Right click the project icon
- New > Folder/Directory
- Call it something like
resourcesorres(or anything else you'd like to call it) - Eclipse: Right click the folder, Build Path > Use as Source Folder
Intellij: Right click the folder, Mark directory as > Sources Root
The folder should now look like the src folder and can now contain images and audio for internal loading
Not implemented yet.
To render a texture, use the Texture.render(...) method, there are many variations of it so choose what suits you. all of them request the Graphics2D g object and the x and y coordinates.
To get audio objects, use the AudioManager class to retrieve IAudioClip instances.
IAudioClip instances have methods such as play(), stop(), pause() and loop().
- Ogg -
AudioManager.Ogg.getClip(String path)(Since: 1.07) - Wave -
AudioManager.Wave.getClip(String path)(Since: 1.11)