Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Vox2D is a simple but powerful 2D graphics library.
Java
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.settings
bin/com/voxelboxstudios/vox2d
src/com/voxelboxstudios/vox2d
target
.classpath
.gitattributes
.gitignore
.project
LICENSE.md
README.md

README.md

Vox2D

Download

Either you compile Vox2D by yourself, or you download the latest .jar located in the target folder.

Overview

Setting up the frame

This code creates your needed frame and launches it.

public class MyFrame extends GameFrame {
  public static void main(String[] args) {
    GameFrame frame = new MyFrame();

    frame.setNormalDisplaySize(1280, 720);
    frame.setTitle("My first game made with Vox2D");

    frame.start();
  }
}

After you extended your class as a GameFrame, these methods will automatically generate:

@Override
public void init(Game g) {}

@Override
public void render(Game g) {}

@Override
public void update(Game g) {}

@Override
public void keyReleased(int keyCode) {}

@Override
public void keyPressed(int keyCode) {}

@Override
public void mouseReleased(int button, int x, int y) {}

@Override
public void mousePressed(int button, int x, int y) {}

Retrieving user input

@Override
public void keyReleased(int keyCode) {
  if(keyCode == Key.X) {
    // The X Key was pressed
  }
}

Loading images and animations

Image     image = new Image("your/image/path.png");
Animation image = new Animation("your/animation/path.png", 20 /* Your duration */, 32 /* Sprite width */);

Rendering

@Override
public void render(Game g) {
  //Drawing an image at 10X and 10Y

  drawImage(image, 10, 10);


  //Drawing an animation at 10X and 10Y
  //NOTICE: Animations have to be updated in the update method, using animation.update()!

  drawAnimation(animation, 10, 10);


  //Drawing text

  drawString("Vox2D is the best library evar!! 1337", 10, 10);


  //You can also align stuff when rendering

  drawImage(image, 10, 10 HAlign.CENTER, VAlign.BOTTOM);


  //Even geometry is supported

  drawOval(x, y, width, height, false);
  drawLine(x1, y1, x2, y2);
  drawRect(x, y, width, height, false);


  //Lets draw a rotated rectangle in the middle of the screen which is filled

  setRotation(45 /** Degrees **/, getWidth() / 2 /** Rotation center X **/, getHeight() / 2 /** Rotation center Y **/)

  drawRect(getWidth() / 2, getHeight() / 2, 100, 100, HAlign.CENTER, VAlign.CENTER, true);


  //Drawing images and animations with custom sizes is possible, too

  drawImage(image, x, y, [HAlign, VALIGN], width, height);
}

Sound

Vox2D also includes a small sound library. You can load and play sound like this:

Sound sound = new Sound("path.wav");

sound.play();

Code snippets

Resolution will not change when scaling or maximizing the window. Because of that we created both a getWidth() and a getHeight() method, to create the best optical rendering possible. You can switch to fullscreen mode by accessing the frame:

this.setFullscreen(true);

Also, you can enable/disable the resizing possibility of your window.

this.setResizable(true);

Because of the resizing, your graphics may not look smooth enough. Using anti aliasing will fix this.

this.setAntiAlias(true);

If you want to hide the cursor, you can use the following snippet.

this.setMouseGrabbed(true);

ALT + F4 isn't always nice, that's why you can set the escape button as the exit button, if you want to.

this.setEscapeToExit(true);

You need the mouse position? No problem!

getGame().getMouseX();
getGame().getMouseY();

To quit the game, use this code.

getGame().exit();

To set your maximum frames per second, use this snippet:

this.setMaximumFPS(60);

Your foreground color can be changed with this code.

this.setColor(YourAWTColor);

You can also change your background color.

this.setBackground(YourAWTColor);

You can also change the selected font by using this snippet.

this.setFont(YourAWTFont);

You can remove all the borders and GUI created from windows by setting the frame undecorated.

this.setDecorated(false);

Example

You can download the latest example which is located in the target folder. The example should look like this:

Example

The great thing about Vox2D is that you can export your project without any problems. It will just run fine as you export it as a runnable JAR file.

Contact

You can reach us every time via email, info@voxelboxstudios.com. We also use skype, my personal account name is sabone.cityblock.

Have fun!

© 2014 Jack Hull

Something went wrong with that request. Please try again.