-
Notifications
You must be signed in to change notification settings - Fork 0
Using libgdx with Clojure
Clojure is a dialect of the Lisp programming language, written for the JVM and with functional programming in mind. Clojure comes with native Java interoperability, making it able to leverage the powerful existing libraries in the Java ecosystem. There are a few existing sources for use of Clojure game development using Libgdx.
This article assumes you have Leiningen installed, along with moderate knowledge of Clojure, or a Lisp. ClojureTV on YouTube has a lot of good videos, specifically Clojure for Java Programmers (Part 2).
Because Libgdx is not hosted on any of Leiningen's default maven repos, we need to add our own, in the Sonatype repos.
(defproject cljdx "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:license {:name "Apache License, Version 2.0"
:url "http://www.apache.org/licenses/LICENSE-2.0.html"
:distribution :repo
:comments "Same as LibGDX"}
:dependencies [[org.clojure/clojure "1.5.1"]
[com.badlogicgames.gdx/gdx "0.9.9-SNAPSHOT"]
[com.badlogicgames.gdx/gdx-backend-lwjgl "0.9.9-SNAPSHOT"]
[com.badlogicgames.gdx/gdx-platform "0.9.9-SNAPSHOT"
:classifier "natives-desktop"]]
:repositories [["sonatype"
"https://oss.sonatype.org/content/repositories/snapshots/"]]
:source-paths ["src/clojure" "src-common/clojure"]
:java-source-paths ["src/java" "src-common/java"]
:aot [cljdx.desktop-launcher]
:main cljdx.desktop-launcher)
The code can be translated in a fairly straightforward manner:
here is the equivalent to Main.java, which we are naming cljdx.desktop-launcher
:
(ns cljdx.desktop-launcher
(:require [cljdx.core])
(:import [com.badlogic.gdx.backends.lwjgl LwjglApplication])
(:gen-class))
(defn -main
[]
(LwjglApplication. (cljdx.core.Game.) "cljdx" 800 600 true))
and here is the Screen implementation (as cljdx.core
)
(ns cljdx.core
(:import [com.badlogic.gdx Game Gdx Graphics Screen]
[com.badlogic.gdx.graphics Color GL20]
[com.badlogic.gdx.graphics.g2d BitmapFont]
[com.badlogic.gdx.scenes.scene2d Stage]
[com.badlogic.gdx.scenes.scene2d.ui Label Label$LabelStyle]))
(declare ^Stage stage)
(def main-screen
(proxy [Screen] []
(show []
(def stage (Stage.))
(let [style (Label$LabelStyle. (BitmapFont.) (Color. 1.0 1.0 1.0 1.0))
label (Label. "Hello world!" style)]
(.addActor stage label)))
(render [delta]
(.glClearColor (Gdx/gl) 0 0 0 1)
(.glClear (Gdx/gl) GL20/GL_COLOR_BUFFER_BIT)
(doto stage
(.act delta)
(.draw)))
(dispose[])
(hide [])
(pause [])
(resize [w h])
(resume [])))
(gen-class
:name cljdx.core.Game
:extends com.badlogic.gdx.Game)
(defn -create [^Game this]
(.setScreen this main-screen))
and thats all the code necessary! a lein uberjar
will generate the required runnable jar!
- The Nightcode clojure and Java IDE provides a wonderful Libgdx clojure template.
- More info would be greatly appreciated, there can certainly be more Polyglot Libgdx out there!
-
Developer's Guide
- Introduction
- Goals & Features
- Community & Support
- Contributing
- Games Built with Libgdx
- Prerequisites
- Gradle Project Setup, Running, Debugging and Packaging
- Project Setup, Running & Debugging
- Third Party Services
- Working from Source
- Using libgdx with other JVM languages
- The Application Framework
- A Simple Game
- File Handling
- Networking
- Preferences
- Input Handling
- Memory Management
- Audio
-
Graphics
- Configuration & Querying Graphics ??
- Fullscreen & VSync
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- Take a Screenshot
- OpenGL ES Support * Configuration & Querying OpenGL ?? * Direct Access ?? * Utility Classes * Rendering Shapes * Textures & TextureRegions * Meshes * Shaders * Frame Buffer Objects
- 2D Graphics * SpriteBatch, TextureRegions, and Sprite * 2D Animation * Clipping, with the use of ScissorStack * Orthographic camera * Mapping Touch Coordinates ?? * Viewports * NinePatches * Bitmap Fonts * Distance field fonts * Using TextureAtlases * Pixmaps * Packing Atlases Offline * Packing Atlases at Runtime * 2D Particle Effects * Tile Maps * scene2d * scene2d.ui * Skin
- 3D Graphics * Quick Start * Models * Material and environment * 3D animations and skinning * Importing Blender models in LibGDX * Perspective Camera ?? * Picking ??
- Managing Your Assets
- Utilities
-
Math Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Path interface & Splines
- Bounding Volumes ??
- Intersection & Overlap Testing ??
- Physics
- Tools
- Extensions
- Deploying your Application
- Building Libgdx ??
- Known Issues
- Articles
- Deprecated (May be outdated)