Skip to content

Instantly share code, notes, and snippets.

View Leejjon's full-sized avatar

Leon Liefting Leejjon

View GitHub Profile
@Leejjon
Leejjon / texturesInScene2dgame.md
Last active October 23, 2024 03:00
How to organize your stages and textures in your libGDX game

Starting out

If you have started out to build a game with libGDX, you've were probably creating and disposing textures out like this:

public class MyGdxGame extends ApplicationAdapter {
    SpriteBatch batch;
    Texture badlogic;

    @Override

public void create () {

@Leejjon
Leejjon / combiningTextureEnumWithAssetManager.md
Created March 1, 2017 01:46
Combining the AssetManager with a Texture enumeration

After my previous gist about handling textures in a libGDX game, I am going to combine the libGDX AssetManager with my approach to see if we can get the best of both worlds.

Asset manager

LibGDX has an AssetManager included, in which you can put all your assets, and it will load them for you. After that, you can retrieve them for actually using them. Disposing the asset manager will dispose all textures inside it nicely.

Positives of using an asset manager:

  • Synchronous and Asynchronous asset loading.
  • All assets in one asset manager (fonts, textures, skins, sound files etc).
  • Support for unloading when pausing and resuming your game.
  • Can be extended and since LibGDX is opensource you can alter it.
@Leejjon
Leejjon / Main.java
Created July 6, 2019 13:42
Main.java with hostname and port as arguments
package com.example;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import java.net.URI;
/**
* Main class.
@Leejjon
Leejjon / Main.java
Created August 2, 2019 21:11
Main file now boot up in production or local mode
package com.example;
import com.example.controller.MyResource;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import java.net.URI;
import java.util.logging.Handler;
import java.util.logging.Level;
@Leejjon
Leejjon / index.tsx
Created July 2, 2020 20:52
index.tsx file with update mechanism for the service worker
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import {Config} from "./serviceWorker";
ReactDOM.render(
<React.StrictMode>
<App />