Skip to content

Getting Started

Sven Arends edited this page Aug 27, 2017 · 6 revisions

Introduction

LibZ is an 2D game library written in pure Java.
With LibZ making games becomes easy.
And it's FREE. That means no monthly costs and no royalty fee.


Setting up your project

Download the latest build of LibZ at: https://github.com/winspeednl/LibZ/releases/latest/
Once you have downloaded it, open eclipse (Or any other IDE | We describe it for eclipse here)
Create an new 'Java Project' And give it a name.
Click 'Next >' and then on 'Libraries > Add External JARs...' and select your downloaded LibZ.jar

Now you have loaded The Library and you are ready to make your project, Easy isn't it?
Right-Click the folder named 'src' and Click 'New > Package' and give it an name.
After that Right-Click your package and Click 'New > Class' And give it a name (IE. Main)

Let's create a directory for the textures/sounds.
Right-Click on your project directory and Click 'New > Source Folder' and call it 'res'.
place all your textures and sound files in that folder.

Once you have that go ahead go to the next section because you're done with the setup :D


The Main class

We use in this section 'Main.java' As the main class.
To be able to run your game , you need the function 'main'
public static void main(String[] args) { ... }
Inside there put GameCore gc = new GameCore(new Game()); // Where new Game() is your main game class
Between here you can put your settings, take a look at Settings for more.
gc.start(); // Start your game

Settings

Some settings are required but most are optional.
If you are using fullscreen use Settings.fullscreen = true;
Otherwise use Settings.width = WIDTH; Settings.height = HEIGHT;

Settings.title = "TITLE"; Set the window and mainmenu title.
Settings.version = "0.1"; Set the game version.
Settings.width = 800; Set the window width.
Settings.height = 600; Set the window width.
Settings.fpsLimit = 60; FPS limit
Settings.splashDisplayTime = 800; How long does the LibZ logo .
Settings.fullscreen = false; Use fullscreen?
Settings.decorated = true; Window borders?
Settings.resizable = true; Resizable game window?
Settings.splash = true; Show LibZ logo before the game starts.
Settings.menu = true; Use default menu?
Settings.closeConfirmation = true; Show a warning before exiting the game?
Settings.isRunning = false; Is the game running?
Settings.debug = false; Show debug?
Settings.libzOverlay = true; Use the LibZ overlay

The Game class

We use in this section 'Game.java' As the game class.
After you created your Game class you will have the default class, we need to change that before we continue.
Begin by extending 'LibZ'
public class Game extends libZ {
After that you need three functions: init, update and render.
public void init(GameCore gc) { ... }
public void update(GameCore gc) { ... }
public void render(GameCore gc, Render r) { ... }

once you have that it's time to create the game yay!


Tiled map loading

To load a map.
TiledMap tiledMap = new TiledMap("PATH"); PATH on filesystem not inside JAR
Update animated tiles.
tiledMap.update();
Render tiles.
tiledMap.renderBackground(render, Screen); render: Render class, Screen boolean: false: Render background color the size of the map | true: Render the background color the size of the screen.
tiledMap.render("LAYERNAME", gc, r); Render a layer.
Looping over ObjectGroups.
for (TiledObject objGroup : tiledMap.getObjectGroup("Collision")) {...}

TiledObject (ObjectGroup)

objGroup.name - String
objGroup.type - String
objGroup.id - Integer
objGroup.x - Float
objGroup.y - Float
objGroup.width - Float
objGroup.height - Float
objGroup.color - Color


Sound

What is a game without sound.
To create a new sound, go to your 'Game' class and create a new field
public Sound jump = new Sound("/Jump.wav"); // '/Jump.wav' refers to 'res/Jump.wav'
Now you have an sound, you could play it back using jump.play();. Easy as pie, Right?