<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Joseph Kavanagh on Medium]]></title>
        <description><![CDATA[Stories by Joseph Kavanagh on Medium]]></description>
        <link>https://medium.com/@joekvngh?source=rss-11af61a3d8a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Joseph Kavanagh on Medium</title>
            <link>https://medium.com/@joekvngh?source=rss-11af61a3d8a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 05:44:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joekvngh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[LibGDX Beyond the Basics]]></title>
            <link>https://medium.com/@joekvngh/libgdx-beyond-the-basics-6130d5d20e21?source=rss-11af61a3d8a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/6130d5d20e21</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[libgdx]]></category>
            <dc:creator><![CDATA[Joseph Kavanagh]]></dc:creator>
            <pubDate>Mon, 20 Mar 2017 04:23:45 GMT</pubDate>
            <atom:updated>2017-03-20T04:23:45.169Z</atom:updated>
            <content:encoded><![CDATA[<p>In my last blog post I went over how to set up a libGDX project and how to run a very basic example. In the last half of that post I went over a few concepts related libGDX such as polling, coordinates and delta time. In this blog post I intend to expand on the last half of my previous post and will go over some other classes and concepts important to libGDX.</p><p><strong>Game State Manager</strong></p><p>A typical game is not just confined to a single screen or a certain level. It usually has multiple levels, menus and a title screen. To achieve this kind of game in libGDX we need to look at a concept called the game state manager.</p><p>In most game engines there is something called a game loop and libGDX has one too. In libGDX you have a method named “render()”. This method is called every time libGDX tries to update what’s on the screen. Your game logic is usually contained here. For example you want to check if the left key is down and if it is, move the player left, you need this logic to be checked every time the computer tries to update the screen so if your finger is on the left key the movement is displayed.</p><p>The game state manager manages states (go figure). Think of states as screens or even better think of them as different versions of the render method. The game state manager can swap out these versions of the render method to display different things on the screen and have different game logic running behind the scenes. Say you have a main menu displayed, when you click the play button a call would be sent to the game state manager to switch the state to play and the render method would also be switched causing the menu to no longer be displayed replaced, instead, by whatever the play state’s render method contains.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*X0GOQijeFX18j9risdke4A.png" /><figcaption>libGDX “game loop” with and without a game state manager(gsm)</figcaption></figure><p>LibGDX provides two classes to help you create a game state manager system. <a href="https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Game.html">Game</a> and <a href="https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Screen.html">Scene</a>. The Game is an abstract class which your game state manager class will extend. The important thing to note in the Game class is that it has a variable of type Scene (we will get to this in a second) and in its render method it calls the Scene’s render method “Scene.render().” Scene is an interface that you implement for all of your state classes. It requires that these classes contain a render method. So on the occasion you want to switch states you simply reassign the Game class’s Scene variable and the Game class will begin calling the render method from that specific state class.</p><p><strong>Important Classes</strong></p><p><em>The Texture class</em></p><p><a href="https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Texture.html">This class</a> decodes an image so that it can be loaded into GPU memory. Essentially you assign your texture object an image from your assets folder and this allows the image to be understood by OpenGL and drawn onto the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*3RHtJ8nZM_FDMFr0NoMRcg.png" /><figcaption>A typical texture</figcaption></figure><p><em>The TextureRegion class</em></p><p><a href="https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/TextureRegion.html">This class</a> holds the coordinates of a rectangle within a texture as well as a reference to the texture object. In libGDX you want to have as many of your game assets on one texture as you can. This is because it is less efficient to have multiple textures (think images) being sent to OpenGL for rendering then just certain regions (TextureRegion) of one. So with all your game assets held in one texture a texture region defines the area of single picture that you can send to the screen to be rendered. Arrays of texture regions are useful for animations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*_8H1HlVXdvcGrMdcHVb9ww.png" /><figcaption>Red rectangle represents a texture region</figcaption></figure><p><em>Animation class</em></p><p><a href="https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Animation.html">This class</a> gives you the ability to define a set of frames for a 2D animation as well as set the amount of time between each frame and to set whether this animation will loop or not. Animations can be given an array of texture regions to play back. Using a method within the animation class you can send the time that has passed in seconds and the method will check to see whether enough time has passed to switch to the next frame. If enough time has passed it returns the next frame (texture region) if not it returns the current frame (texture region).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*kkte6MhMTJ9dteCYckNGdg.png" /><figcaption>Animation</figcaption></figure><p><em>Sprite class</em></p><p><a href="https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html">Sprite</a> holds a texture, texture region or animation, and its position on the screen. It also allows you to specify the width and height of the texture/texture region. The sprite class gives your image a position on the screen. It is usually used with an animation method providing the image so the current frame is displayed in the proper position onscreen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*N0pOdKYlryPLsC1BBAgeCA.png" /><figcaption>A Sprite on a screen</figcaption></figure><p>I hope this provided a little more information on some of the important concepts and classes of libGDX. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6130d5d20e21" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Example “Game” in LibGDX]]></title>
            <link>https://medium.com/@joekvngh/example-game-in-libgdx-f044d19b58fd?source=rss-11af61a3d8a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f044d19b58fd</guid>
            <category><![CDATA[libgdx]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Joseph Kavanagh]]></dc:creator>
            <pubDate>Mon, 27 Feb 2017 05:31:13 GMT</pubDate>
            <atom:updated>2017-02-27T05:31:13.402Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog post we are going to cover two main topics. Setting up a libGDX project in Eclipse and creating an example in libGDX. This blog post will assume you have Eclipse already installed and have the Java Development Kit 7 or higher installed.</p><p><strong>Setting up a libGDX Project</strong></p><p>To create a libGDX project in Eclipse you are first going to need a <a href="https://github.com/libgdx/libgdx/wiki/Setting-up-your-Development-Environment-%28Eclipse%2C-Intellij-IDEA%2C-NetBeans%29">few things</a>. For Eclipse you will need to download and install the Android SDK and the Android Development Tools for Eclipse plugin. Though these are optional if you don’t plan to deploy to android. The last thing you need is the libGDX setup application which can be downloaded from the <a href="http://libgdx.badlogicgames.com/download.html">libGDX website</a>. The setup application is a jar file which lets you select and customize your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*D-cruG5gEHulvcHQWmra7A.png" /><figcaption>LibGDX setup application</figcaption></figure><p>When you open the setup application you will see text boxes to enter the name of your game, package hierarchy and your main class. You will then need to select where the project folder will be created. If you want your game to be Android compatible you will need to enter the path of the Android SDK you downloaded previously. Next you can select which platforms you want this game to deploy on. Keep in mind that the IOS options require an apple developers account and a Mac to use properly. You will also be able to pick which extensions you would like to add to your libGDX project by checking off the required box. You can also select third party extensions by clicking the “show third party extensions” button. Then select “advanced” and check off Eclipse project. Finally press “generate”.</p><p><strong>Empty project overview</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*gy6i2Ny1KIEae3OsVW45Bg.png" /></figure><p>Open Eclipse and import the generated project into your workspace. Use the option “import Gradle project.” After the import is complete you will see at least three folders in your project explorer. One will just be what you named your project. This folder contains Gradle related stuff and we won’t be touching this folder for our example. The next folder is the -core folder. This folder contains your main game class and is where you will add all of your code for this example. Depending on which platforms you chose to deploy to, there will be folders for each chosen platform. For example: “projectname-desktop or projectname-android”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*rbADacN1wrFm8kZ6_T-tfA.png" /></figure><p>Select the -core folder and open the java class inside. This is your main game class and by default you will see three methods in it. The create method is where we will initialize our variables. The render method is where our game logic will go as this method is called every time the screen refreshes. Finally, the dispose method is where on close the program will check for a list of objects it needs to erase from memory.</p><p><strong>Example Source Material</strong></p><p>In your main game class delete all existing code inside the class brackets (leave the class, imports and package lines) and copy and paste this example code into your main game class.</p><pre>private static final int FRAME_COLS = 8, FRAME_ROWS = 1;<br> private static final int JUMP_HEIGHT = 20;<br> <br> Animation&lt;TextureRegion&gt; walkRightAnimation;<br> Animation&lt;TextureRegion&gt; walkLeftAnimation;<br> Animation&lt;TextureRegion&gt; waveAnimation;<br> TextureRegion idleFrame;<br> TextureRegion jumpFrame;<br> <br> <br> <br> float stateTime;<br> Texture img;<br> SpriteBatch batch;<br> Sprite sprite;<br> <br> int canJump = 0;<br> float gravity = -2;<br> int jumpCounter = 0;<br> <br> <br> @Override<br> public void create () {<br> //Loads texture (image file) into memory<br> img = new Texture(Gdx.files.internal(“coolguy.png”));<br> <br> //Creates a new sprite batch and splits the it into frames based on our static variables<br> batch = new SpriteBatch();<br> TextureRegion[][] tmp = TextureRegion.split(img, <br> img.getWidth() / FRAME_COLS,<br> img.getHeight() / FRAME_ROWS);<br> <br> <br> //creating a texture region which is an array of areas on img texture this texture region has two frames and the size of those frames is taken from tmp texture regions<br> <br> TextureRegion[] idleFrames = new TextureRegion[1];<br> idleFrames[0] = tmp[0][0];<br> TextureRegion[] walkRightFrames = new TextureRegion[2];<br> walkRightFrames[0] = tmp[0][1];<br> walkRightFrames[1] = tmp[0][2];<br> TextureRegion[] walkLeftFrames = new TextureRegion[2];<br> walkLeftFrames[0] = tmp[0][3];<br> walkLeftFrames[1] = tmp[0][4];<br> TextureRegion[] jumpFrames = new TextureRegion[1];<br> jumpFrames[0] = tmp[0][5];<br> TextureRegion[] waveFrames = new TextureRegion[2];<br> waveFrames[0] = tmp[0][6];<br> waveFrames[1] = tmp[0][7];<br> <br> <br> //Creates a animation and assigns a set of frames as well as a time between each frame<br> walkRightAnimation = new Animation&lt;TextureRegion&gt;(0.25f, walkRightFrames);<br> walkLeftAnimation = new Animation&lt;TextureRegion&gt;(0.25f, walkLeftFrames);<br> waveAnimation = new Animation&lt;TextureRegion&gt;(0.25f, waveFrames);<br> idleFrame =idleFrames[0];<br> jumpFrame =jumpFrames[0];<br> <br> // floating point value this is important!<br> stateTime = 0f; <br> <br> <br> <br> sprite = new Sprite(idleFrame);<br> sprite.setPosition(50, 50);<br> }<br>@Override<br> public void render () {<br> <br> if(Gdx.input.isKeyPressed(Input.Keys.UP))<br> { <br> sprite.setRegion(waveAnimation.getKeyFrame(stateTime, true));<br> }<br> if(Gdx.input.isKeyPressed(Input.Keys.LEFT))<br> { <br> sprite.setRegion(walkRightAnimation.getKeyFrame(stateTime, true));<br> sprite.translateX(-5f);<br> }<br> if(Gdx.input.isKeyPressed(Input.Keys.RIGHT))<br> {<br> sprite.setRegion(walkLeftAnimation.getKeyFrame(stateTime, true));<br> sprite.translateX(5f); <br> }<br> if(Gdx.input.isKeyPressed(Input.Keys.SPACE))<br> {<br> sprite.setRegion(jumpFrame);<br> if(jumpCounter == 0 &amp;&amp; canJump == 0)<br> {<br> canJump = 1;<br> gravity = 8;<br> }<br> else if (canJump == 1 &amp;&amp; jumpCounter &gt;= JUMP_HEIGHT)<br> {<br> canJump = 1;<br> gravity = -2;<br> }<br> }<br> <br> if(!Gdx.input.isKeyPressed(Input.Keys.SPACE))<br> {<br> gravity = -2;<br> }<br> <br> if(!Gdx.input.isKeyPressed(Input.Keys.ANY_KEY))<br> {<br> sprite.setRegion(idleFrame);<br> }<br> <br> <br> if(canJump == 1) jumpCounter++;<br> sprite.translateY(gravity);<br> if(sprite.getY() &lt; 0) <br> {<br> jumpCounter = 0;<br> canJump = 0;<br> sprite.setY(0);<br> }<br> <br> <br> Gdx.gl.glClearColor(1, 1, 1, 1);<br> Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);<br> stateTime += Gdx.graphics.getDeltaTime();<br> batch.begin();<br> batch.draw(sprite, sprite.getX(), sprite.getY(), 200, 180); // Draw current frame at (50, 50)<br> batch.end();<br> }<br> <br> @Override<br> public void dispose () {<br> batch.dispose();<br> img.dispose();<br> }</pre><p>Now save this picture as coolguy.png and copy and paste it into the assets folder of your -desktop folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*TdqGEmeQiby8yF_xD22ciQ.png" /><figcaption>coolguy.png</figcaption></figure><p>Test to make sure this works by navigating to your -desktop java class, right clicking on it and selecting “run as” &gt; “java application”. The example should start and you should see a stick man on screen, moving the arrow keys and pressing the space bar will make him move side to side and jump.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*jI3zLvoCzHx1kPkLCBSKnA.png" /><figcaption>Running the example should result in this</figcaption></figure><p>So what’s going on behind the scenes in this example? Here I will briefly highlight a few concepts of libGDX that are used in this example.</p><p><strong>Polling</strong></p><p>This is <a href="https://github.com/libgdx/libgdx/wiki/Polling">the method</a> I used in my example to read user input. Each time the render method is called the application checks the current state of the input device (keyboard). If a certain key is being pressed it will execute the specific code tied to that scenario. This works fine in most cases, though if someone is pushing a key up and down really fast this method may not register all the key presses.</p><p>An alternative to polling is event handling which allows for chronological and reliable information from input devices and is slightly better performance wise.</p><p><strong>Coordinates</strong></p><p>Different parts of libGDX use different kinds of <a href="https://github.com/libgdx/libgdx/wiki/Coordinate-systems">coordinate grids</a>. In this example I use screen coordinates to specify the location of the stick man. In this coordinate system 0,0 is at the lower left hand corner of the screen. Another example of a coordinate system used in libGDX is the touch coordinates which are used when dealing with mouse or touch (android/IOS) inputs. In this coordinate system 0,0 is in the upper left hand corner of the screen.</p><p><strong>Delta Time</strong></p><p>Delta time in game programming terms is the amount of time since the last render call. In this example I use it to help the animations play at a constant frame rate. Delta time is commonly used to help calculate movement of in game objects so that their movement isn’t tied to the computers processing speed (how fast the computer can call the render method).</p><p>I hope this helped give you a better understanding of how a libGDX project is structured. Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f044d19b58fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intro to LibGDX]]></title>
            <link>https://medium.com/@joekvngh/intro-to-libgdx-3363d9f366e4?source=rss-11af61a3d8a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3363d9f366e4</guid>
            <category><![CDATA[libgdx]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Joseph Kavanagh]]></dc:creator>
            <pubDate>Mon, 30 Jan 2017 06:19:29 GMT</pubDate>
            <atom:updated>2017-01-30T09:10:12.334Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is it?</strong></p><p><a href="http://libgdx.badlogicgames.com/index.html">LibGDX</a> is a framework for developing JVM (java virtual machine) based games or applications. <a href="https://github.com/libgdx/libgdx/wiki/Introduction">The developers themselves</a> don’t really consider libGDX a full game engine in the popular sense. Rather a framework that allows optional lower level access to things like input devices, OpenGL and file systems with the goal being more control and flexibility for the user (you). So to sum libGDX up in a couple of words I would call it a flexible, code driven, game development framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NI-esFxWWMgZ2n8yM5W8Kw.png" /></figure><p><strong>A little History</strong></p><p><a href="http://www.badlogicgames.com/wordpress/?p=3412">LibGDX was started in 2009</a> by Mario Zechner as a personal Android game framework called AFX. Mario wanted an easy way to prototype the games he was creating without having to spend the time deploying them to Android. So he modified his framework to run both on android and desktop environments. This was kind of the foundation of libGDX.</p><p>It took 4 years to get to the 1.0 release. During that time libGDX became a fleshed out cross platform game framework. With support for IOS, Windows, Mac OS X, Linux and Android. It got an open source license and the source code was migrated over to GitHub. This led to many more people contributing to the project and over this period of time a lot of new features and extensions were added.</p><p>After 1.0 there has been a steady stream of updates with the latest release, <a href="http://www.badlogicgames.com/wordpress/?p=3980">libGDX 1.9.5</a>, releasing on December 11, 2016. In December of 2015 libGDX even had its own <a href="https://itch.io/jam/libgdxjam">game jam</a> which drew in 83 submissions. On its website it currently has over <a href="http://libgdx.badlogicgames.com/gallery.html">4000 games</a> in the gallery. This gallery showcases games made in libGDX and I think it really demonstrates that libGDX has become a popular framework for game development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*KkAzy2LTtQoYB3NPqAEaFA.png" /></figure><p><strong>Key Features</strong></p><p>-<a href="https://github.com/libGDX/libGDX"><em>Open Source</em></a></p><p>LibGDX is licensed under the Apache 2.0 License. This is a permissive license meaning you can modify and distribute the source code of libGDX freely provided you include the original license text. In terms of games you make with libGDX, you are free to sell the games you make and don’t have to give anything back to the libGDX creators.</p><p>-<a href="http://libgdx.badlogicgames.com/features.html"><em>Cross Platform</em></a></p><p>A major draw or “selling point” of libGDX is its cross platform publishing capability. One of the core principles of the framework is the ability to write your code once and with minimal additional code have your application run on IOS, Android, HTML, Windows or Linux. It’s able to do this through its multiple back-end libraries that take your code and interpret it for the specific operating system you want to deploy to. The grand idea being that you won’t have to have a lot of platform specific code for your application.</p><p>From what I have read online the HTML back-end can be difficult to use and I wouldn’t recommend using libGDX if you plan to only develop for web. Though as an added platform to publish on it’s doable.</p><p><a href="http://www.gamefromscratch.com/post/2016/04/15/RoboVM-is-Dead.aspx">There was recently a set back</a> to the cross platform publishing easiness of libGDX. Their back-end technology to publish on IOS, RoboVM, was killed off by Microsoft when they bought RoboVM’s parent company Xamerin. This has led to two new back-ends for publishing on IOS. Both work at the moment, though they haven’t been around that long and may need some time to be brought fully up to date with new IOS features.</p><p>-<a href="http://libgdx.badlogicgames.com/features.html"><em>Extensions</em></a></p><p>LibGDX has a many extensions available right from its own setup application. These add things like 2D physics, AI frameworks and level editors. They extend the functionality of the framework. For example, if you need 3D physics in your game, you just need to include the Bullet physics extension when you create your project instead of programing something like that from scratch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*1fbF1uV3VMmIIKD65MiiiA.png" /></figure><p><strong>Getting started</strong></p><p>To follow along with the upcoming blog posts and to begin messing around with the libGDX framework you will need to make sure you have a <a href="https://github.com/libgdx/libgdx/wiki/Setting-up-your-Development-Environment-%28Eclipse%2C-Intellij-IDEA%2C-NetBeans%29">few things. </a>First you will need an IDE. I will be using Eclipse though libGDX also supports Android Studio, Intellij IDEA and NetBeans. Second you’re going to need at least JDK (Java Development Kit) 7 installed. The third thing is Gradle integration, which I believe comes built in with the Java version of Eclipse neon. Next we will need both the Android SDK and the ADT Plugin for Eclipse. Finally, we can’t forget the libGDX project setup application. And that’s it! I will talk in a lot more detail on setting this up in my next blog. Keep in mind that this setup does not allow for publishing on IOS unless your using a Mac.</p><p>I hope this introduction gave you a feel of what libGDX is and its capabilities. In my next blog I will be going through the setup of libGDX and creating a small example application. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3363d9f366e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>