<?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 Simone Cavazzoni on Medium]]></title>
        <description><![CDATA[Stories by Simone Cavazzoni on Medium]]></description>
        <link>https://medium.com/@cavazzoni.simone.98?source=rss-d4dc620f28b3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*yxBt-2xyerEyQmaO.</url>
            <title>Stories by Simone Cavazzoni on Medium</title>
            <link>https://medium.com/@cavazzoni.simone.98?source=rss-d4dc620f28b3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 04:41:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cavazzoni.simone.98/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[Getting started with Android Games w/o frameworks]]></title>
            <link>https://medium.com/@cavazzoni.simone.98/getting-started-with-android-games-w-o-frameworks-f927e9661770?source=rss-d4dc620f28b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f927e9661770</guid>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-game-development]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[android-games]]></category>
            <dc:creator><![CDATA[Simone Cavazzoni]]></dc:creator>
            <pubDate>Tue, 30 Jan 2018 15:29:06 GMT</pubDate>
            <atom:updated>2018-02-08T20:47:20.329Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently built a simple Android game (<a href="https://play.google.com/store/apps/details?id=com.simonecavazzoni.firstandroidgame"><strong>Endless Cube</strong></a>) to discover what could I achieve without any framework. Today we’ll walk through what I learned from this project.</p><ul><li><a href="https://github.com/Zimm1/Endless-Cube"><strong>GitHub</strong></a></li><li><a href="https://play.google.com/store/apps/details?id=com.simonecavazzoni.firstandroidgame"><strong>Play Store</strong></a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g6webZYO15ulpMKcEt15aA.png" /></figure><h3>Let’s make a game… What game? 👾</h3><p>The first concept of the game was a level-based auto-scrolling platformer, where the player would only have to jump at the right time and/or bounce off walls and ceilings. The only thing that I didn’t like was that the device had to be in landscape orientation, and for this reason the player was less likely to play one-handed because that’s just not comfortable at all.</p><p>So I decided to force the portrait format:</p><pre>// AndroidManifest.xml</pre><pre>&lt;activity<br>    ...<br>    android:screenOrientation=&quot;portrait&quot;&gt;</pre><p>I also wanted to let the user play the game with only one thumb, and all the jumping and bouncing of the initial idea weren’t a good fit.</p><p>I finally settled down on the player character simply following the position of the finger on the screen, in order to avoid obstacles coming towards it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ikBggHqIyyPhSJXyr449pQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3F25y8srWfFiMo5orgeExA.png" /></figure><h3>Object-Oriented programming for days 💪</h3><p>I desperately needed a way to keep track of all the props on the screen, so I though: “Every prop must have a position, a dimension, a method to update all the information every frame update and a method to draw its shape… Why don’t I create a super class?”</p><p>And that’s what I did:</p><pre>// GameProp.java</pre><pre>public abstract class GameProp {<br>    private TupleFloat position;<br>    private TupleFloat dimension;<br>    ...<br>    public void update() {<br>        ...<br>    }<br>    public void draw() {<br>        ...<br>    }<br>    ...<br>}</pre><p>I could then code all other game props extending this parent class:</p><ul><li><strong>GamePropPlayer</strong></li><li><strong>GamePropObstacle</strong></li><li><strong>GamePropBackground</strong></li><li><strong>GamePropPointsLine</strong></li><li><strong>…</strong></li></ul><h3>SurfaceView and Canvas, your new best friends ❤️</h3><p>Once I got the basic logic down, I had to display the props. That’s where these friends came in handy.</p><h4>SurfaceView</h4><p>I crated the class “<em>MySurfaceView” </em>which extends the base <strong>SurfaceView</strong> and overrides the methods to react to creation (<em>surfaceCreated</em>), changes (<em>surfaceChanged</em>), destruction (<em>surfaceDestroyed</em>) and touch input (<em>onTouchEvent</em>). I then coded some methods to handle the game loop:</p><pre>// MySurfaceView.java</pre><pre>public class MySurfaceView extends SurfaceView<br>        implements SurfaceHolder.Callback {<br>    ...<br>    public synchronized void startGameLoop() {<br>        ...<br>    }<br>    public synchronized void stopGameLoop() {<br>        ...<br>    }<br>    private TimerTask getGameLoopTask() {<br>        ....<br>    }<br>    ...<br>}</pre><p>Game-loop stop and start are declared synchronized in order to avoid issues caused by modifying the same class parameters at the same time.</p><h4>Canvas</h4><p>The “<em>getGameLoopTask”</em> method returns a TimerTask that can be executed asynchronously every N milliseconds. The task locks the canvas, executes one frame and unlocks the canvas, in order to display the changes:</p><pre>// MySurfaceView.getGameLoopTask()</pre><pre>if (isGameLoopGoing &amp;&amp; gameEngine != null) {<br>    Canvas c = getHolder().lockCanvas();<br>    if (c != null) {<br>        gameEngine.gameLoop(timeScale, c);<br>    }<br>    try {<br>        getHolder().unlockCanvasAndPost(c);<br>    } catch (Exception e) {<br>        //Log.e(&quot;Error&quot;, &quot;IllegalState&quot;, e);<br>    }<br>}</pre><h3>GameEngine.State == End? Not yet 😐</h3><p>The core gameplay was now ready, but it missed some user interface, like a welcome screen and a menu. So I created a “<em>GameState” </em>parent class, which has methods to control all the props for a certain scene of the game.</p><pre>public abstract class GameState {</pre><pre>    ...    </pre><pre>    public void draw(Canvas c) {}</pre><pre>    public void update(float timeScale) {}</pre><pre>    public synchronized boolean onInput(GameInput input) {<br>        return false;<br>    }</pre><pre>    public void onResize(Rect surfaceRect) {<br>        this.surfaceRect = surfaceRect;<br>    }</pre><pre>    ...<br>}</pre><p>Then, I extended this class to compose all the scenes for my game:</p><ul><li><strong>GameStateStart</strong></li><li><strong>GameStatePlaying</strong></li><li><strong>GameStateEnd</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K8cqQEgxFg9IljVvxlpIJQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jpg78kKkjVweCeLmxp03EA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUZvvP7aLWAdnYf1nXy92A.png" /></figure><h3>My high-score is better than yours 😛</h3><p>Another must for me was the integration with Google Play Games, so I created a new project on Play Games Console and added a leaderboard for high scores, and some achievements. I then implemented the logic to handle scores and achievements in the transition between “<em>GameStatePlaying</em>” and “<em>GameStateEnd</em>”. Finally, I added two buttons in the main menu (<em>GameStateStart</em>) to enable the user to check his/her progress with the default activities provided by the Google Play Games library.</p><h3>And Finally 😄</h3><p>The app was ready! In order to complete the project I created some graphics and a description for the Play Store.</p><p>I hope this article made you understand how a framework-less Android Game works under the hood. 👍</p><p>Until next time, bye! 👋</p><p><strong>About the author, </strong><a href="https://medium.com/u/d4dc620f28b3"><strong>Simone Cavazzoni</strong></a><strong>:</strong></p><ul><li><a href="https://simonecavazzoni.com/"><strong>Website</strong></a></li><li><a href="https://www.linkedin.com/in/simone-cavazzoni/"><strong>LinkedIn</strong></a></li></ul><p>Thanks for reading.</p><blockquote>If you enjoyed this article, please feel free to hit that clap button 👏 to help others find it.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f927e9661770" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>