<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>Comments on: Coding a Space Invaders Game in Kotlin</title>
	<atom:link href="https://gamecodeschool.com/kotlin/coding-a-space-invaders-game-in-kotlin/feed/" rel="self" type="application/rss+xml" />
	<link>https://gamecodeschool.com/kotlin/coding-a-space-invaders-game-in-kotlin/</link>
	<description>Game Coding for Beginners</description>
	<lastBuildDate>Mon, 20 Apr 2026 12:04:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>By: Timba</title>
		<link>https://gamecodeschool.com/kotlin/coding-a-space-invaders-game-in-kotlin/#comment-17327</link>
		<dc:creator><![CDATA[Timba]]></dc:creator>
		<pubDate>Tue, 01 Dec 2020 00:33:54 +0000</pubDate>
		<guid isPermaLink="false">http://gamecodeschool.com/?p=16045#comment-17327</guid>
		<description><![CDATA[Can anyone explain how in KotlinInvadersView, setting &quot;paused&quot; to false calls the &quot;Pause&quot; method?]]></description>
		<content:encoded><![CDATA[<p>Can anyone explain how in KotlinInvadersView, setting &#8220;paused&#8221; to false calls the &#8220;Pause&#8221; method?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Francis</title>
		<link>https://gamecodeschool.com/kotlin/coding-a-space-invaders-game-in-kotlin/#comment-17303</link>
		<dc:creator><![CDATA[Francis]]></dc:creator>
		<pubDate>Sat, 05 Sep 2020 23:05:37 +0000</pubDate>
		<guid isPermaLink="false">http://gamecodeschool.com/?p=16045#comment-17303</guid>
		<description><![CDATA[Hey Jon,

Steve partially addressed some of your issues in the comment above, but let me try to add some clarity as well:

1) Null Checks (where you added !!):
This is due to the way that the Bitmaps are being initialized. Using a question mark means the variable could be holding a null value. Kotlin tries its best to avoid the dreaded NullPointerException that has plagued Java for oh so long and so gives you compiler warnings saying the value can&#039;t be used since it might be null. You can either add a check to ensure the value isn&#039;t null, use !! (like you did) which is you telling the compiler, &quot;I&#039;m 110% certain this value will never be null, ever!&quot; and will crash your app if you lied, or you could use a lateinit expression to tell the compiler that you&#039;re not going to initialize the value just yet, but you promise to do it later. 

Fix: https://github.com/EliteIntegrity/Kotlin-Invaders/pull/3/files


2) Removing the App Title Bar
This is likely due to the IDE you used to generate your main activity class. Android Studios (and potentially other IDEs) will create a class that inherits from AppCompatActivity() by default. The code in this tutorial was written so that KotlinInvadersActivity inherits from Activity(). The fix here is to simply update your main activity to inherit from Activity() instead of AppCompatActivity().

Fix: https://github.com/EliteIntegrity/Kotlin-Invaders/blob/master/kotlininvaders/KotlinInvadersActivity.kt#L7


3) Perpetual Motion
The issue where the ship doesn&#039;t stop moving is a simple logic bug (nothing to do with your device). The logic for moving the ship triggers if you touch the bottom 1/8th of the screen, but the logic to stop the ship moving only triggers if you let go on the bottom 1/10th of the screen. Meaning there&#039;s a small area (1/40th of the screen above the bottom 1/10th of the screen) where the movement logic can be triggered, but not un-triggered.

This is a great example of why DRY (Don&#039;t Repeat Yourself) code is so important. The code `size.y - size.y / 8` was intended to be used 3 times in rapid succession. Likely while the author was tuning the code and updated the first 2 instances, but missed the last which resulted in a bug. Extracting that value out into a local variable at the start of the onTouchEvent function would a) make tuning easier and b) avoid the chance of creating this type of bug again.

Fix: https://github.com/EliteIntegrity/Kotlin-Invaders/pull/1/files]]></description>
		<content:encoded><![CDATA[<p>Hey Jon,</p>
<p>Steve partially addressed some of your issues in the comment above, but let me try to add some clarity as well:</p>
<p>1) Null Checks (where you added !!):<br />
This is due to the way that the Bitmaps are being initialized. Using a question mark means the variable could be holding a null value. Kotlin tries its best to avoid the dreaded NullPointerException that has plagued Java for oh so long and so gives you compiler warnings saying the value can&#8217;t be used since it might be null. You can either add a check to ensure the value isn&#8217;t null, use !! (like you did) which is you telling the compiler, &#8220;I&#8217;m 110% certain this value will never be null, ever!&#8221; and will crash your app if you lied, or you could use a lateinit expression to tell the compiler that you&#8217;re not going to initialize the value just yet, but you promise to do it later. </p>
<p>Fix: <a href="https://github.com/EliteIntegrity/Kotlin-Invaders/pull/3/files" rel="nofollow">https://github.com/EliteIntegrity/Kotlin-Invaders/pull/3/files</a></p>
<p>2) Removing the App Title Bar<br />
This is likely due to the IDE you used to generate your main activity class. Android Studios (and potentially other IDEs) will create a class that inherits from AppCompatActivity() by default. The code in this tutorial was written so that KotlinInvadersActivity inherits from Activity(). The fix here is to simply update your main activity to inherit from Activity() instead of AppCompatActivity().</p>
<p>Fix: <a href="https://github.com/EliteIntegrity/Kotlin-Invaders/blob/master/kotlininvaders/KotlinInvadersActivity.kt#L7" rel="nofollow">https://github.com/EliteIntegrity/Kotlin-Invaders/blob/master/kotlininvaders/KotlinInvadersActivity.kt#L7</a></p>
<p>3) Perpetual Motion<br />
The issue where the ship doesn&#8217;t stop moving is a simple logic bug (nothing to do with your device). The logic for moving the ship triggers if you touch the bottom 1/8th of the screen, but the logic to stop the ship moving only triggers if you let go on the bottom 1/10th of the screen. Meaning there&#8217;s a small area (1/40th of the screen above the bottom 1/10th of the screen) where the movement logic can be triggered, but not un-triggered.</p>
<p>This is a great example of why DRY (Don&#8217;t Repeat Yourself) code is so important. The code `size.y &#8211; size.y / 8` was intended to be used 3 times in rapid succession. Likely while the author was tuning the code and updated the first 2 instances, but missed the last which resulted in a bug. Extracting that value out into a local variable at the start of the onTouchEvent function would a) make tuning easier and b) avoid the chance of creating this type of bug again.</p>
<p>Fix: <a href="https://github.com/EliteIntegrity/Kotlin-Invaders/pull/1/files" rel="nofollow">https://github.com/EliteIntegrity/Kotlin-Invaders/pull/1/files</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Horton</title>
		<link>https://gamecodeschool.com/kotlin/coding-a-space-invaders-game-in-kotlin/#comment-17239</link>
		<dc:creator><![CDATA[John Horton]]></dc:creator>
		<pubDate>Wed, 04 Mar 2020 15:45:48 +0000</pubDate>
		<guid isPermaLink="false">http://gamecodeschool.com/?p=16045#comment-17239</guid>
		<description><![CDATA[Hi Jon,

Regarding the ship keeping moving it is because the controls are too simplistic. Try to make sure that only one finger is in contact with the screen at any one time. 
!! is interesting but too big to talk about here. Take a look at this article.https://kotlinlang.org/docs/reference/null-safety.html

Thanks for your kind comment]]></description>
		<content:encoded><![CDATA[<p>Hi Jon,</p>
<p>Regarding the ship keeping moving it is because the controls are too simplistic. Try to make sure that only one finger is in contact with the screen at any one time.<br />
!! is interesting but too big to talk about here. Take a look at this article.<a href="https://kotlinlang.org/docs/reference/null-safety.html" rel="nofollow">https://kotlinlang.org/docs/reference/null-safety.html</a></p>
<p>Thanks for your kind comment</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Felkin</title>
		<link>https://gamecodeschool.com/kotlin/coding-a-space-invaders-game-in-kotlin/#comment-17238</link>
		<dc:creator><![CDATA[Jon Felkin]]></dc:creator>
		<pubDate>Tue, 03 Mar 2020 18:17:27 +0000</pubDate>
		<guid isPermaLink="false">http://gamecodeschool.com/?p=16045#comment-17238</guid>
		<description><![CDATA[Thank you very much for this tutorial I got everything working, there were a few lines that gave me errors, as you can see here,
canvas.drawBitmap(Invader.bitmap2!!,
                            invader.position.left,
                            invader.position.top,
                            paint)
I had to add the !! after Invader.bitmap2, think there were 4 locations that I could not get working without adding these. Also trying to get rid of the title bar was a nightmare I eventually found a way to do it with the styles.xml that did not crash the program, I am really clueless as to why neither of these things worked for me but I got through it. 
Also sometimes (20-30% of the time) the ship keeps on moving when I have stopped touching the screen, I am unsure why this is and might just be my phone.

I am still learning so working through this was very helpful and I thank you for putting so much time into the tutorial for us.]]></description>
		<content:encoded><![CDATA[<p>Thank you very much for this tutorial I got everything working, there were a few lines that gave me errors, as you can see here,<br />
canvas.drawBitmap(Invader.bitmap2!!,<br />
                            invader.position.left,<br />
                            invader.position.top,<br />
                            paint)<br />
I had to add the !! after Invader.bitmap2, think there were 4 locations that I could not get working without adding these. Also trying to get rid of the title bar was a nightmare I eventually found a way to do it with the styles.xml that did not crash the program, I am really clueless as to why neither of these things worked for me but I got through it.<br />
Also sometimes (20-30% of the time) the ship keeps on moving when I have stopped touching the screen, I am unsure why this is and might just be my phone.</p>
<p>I am still learning so working through this was very helpful and I thank you for putting so much time into the tutorial for us.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Horton</title>
		<link>https://gamecodeschool.com/kotlin/coding-a-space-invaders-game-in-kotlin/#comment-17146</link>
		<dc:creator><![CDATA[John Horton]]></dc:creator>
		<pubDate>Fri, 01 Nov 2019 09:01:06 +0000</pubDate>
		<guid isPermaLink="false">http://gamecodeschool.com/?p=16045#comment-17146</guid>
		<description><![CDATA[Hi Steve,

Thanks for your tips they are very useful. I will publish them here so they might help future readers.]]></description>
		<content:encoded><![CDATA[<p>Hi Steve,</p>
<p>Thanks for your tips they are very useful. I will publish them here so they might help future readers.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
