Welcome to My Blog!

Thank you for visiting my Blog! I created this blog to help people. My intentions are to share solutions I've found to problems in hopes it would save others time, and from headaches :0). I'm also going to share other interesting things I find in my home life, and work life. I hope you find what I've shared to be interesting. Enjoy your visit!


Friday, August 24, 2018

Entering the Game Programming World

Story
I've recently gotten into Game programming for mobile devices. I first searched for books that taught how to build TD (tower defense) games, because those are my favorite to play on mobile devices. I found an outdated one on eKobo, and another one on Amazon Kindle. They were very cheap, around $6-$7, and I think eKobo gave me a coupon for $5, so I ended up paying around $1.50 for the book, and the one on Amazon was around $2-$3.

I ended up reading the one from eKobo first, and the tutorial took me to YoYo's GameMaker. I ended up downloading it, and installing it.  I followed the tutorial about half way, bringing in my own assets/graphics for the towers, and I drew new bullets for them using Paint.NET.  I only got as far as putting in a background, a tower, a monster for the tower to shoot at. It was neat how easy it was to do all of that with only copying and pasting a few lines of the sample code.  I was up to 2am working on it, as it was so much fun!  I was going to continue working on it the next day.  Before going to bed, I looked into the pricing for using the GameMaker to deploy to Android and Apple phones, and it was around $400, steep! but it was a one time payment for the license.

Next morning, I woke up, and thought, do I really want to invest all my time and learning into the GameMaker platform? Is it the best platform (Game Engine) to learn? That's when I decided that maybe before I do that I should research to see if there are other platforms out there, what their capabilities are, and pricing.  I spent the morning doing that, mostly did a search for top GameMaker platforms/software, and I checked out a listing that stated "Top 8 Game Engines", "Top 5 Game Engines", and one other.

Choice of Game Engine
Long story short, after investigating all the game engines, and pricing plans. I decided to choose "Unity", because it doesn't require you to pay anything until you have revenue of $100,000, or more. It is popular. And it seems many have used it to create games of many genres.  It seems from the reviews I read that Unreal Game Engine was harder to use if you hadn't been using it all along, which wasn't the case with "Unity".

I didn't like the pricing plan for Unreal either. Also, it was stated in a review or 2 that it was a much steeper learning curve to learn how to use the Unreal Game Engine.

Tutorials
Seems I shouldn't have bought those online books after all, there are plenty of free resources online via Unity, google, and Youtube for people wanting to teach you how to program a TD game. I remember trying to build one years ago, and there weren't as many tutorials, well back then, I actually only found one, and it was teaching using a grid, it shrunk everything down to the bit level, which was horrible.

I worked my way through the interactive tutorials that were built into the Unity Installer, they were pretty neat, but didn't go into how to develop the game. It just walked you through making small changes to fix certain things in a mini-game.

I then jumped into trying to follow an "Intermediate" level tutorial for programming the "Tower Defense" type game, which is what I really wanted to learn from the get-go, but the instructions were really high level, and I just couldn't follow, since I'm very much a beginner.  So, I decided to start at square 1, and choose a tutorial at the "Beginner Level".

So, I worked my way through "Roll a ball", pretty cool what you can do with this Unity IDE, and this is only the beginning.  After creating my game, I had so many issues with building the game, and deploying it to my phone, error after error.  I'll outline my steps at a high level below, hopefully it will help some of you out there trying to start game programming.

Procedure
1. Download and install the latest version of "Unity"
* https://unity3d.com/get-unity/download
* Click, choose your unity and download

2. Download and install the latest version of "Android SDK Manager"
* this part can take a long time if you are crazy like me, and want to install everything.  It probably took 1-2 days for me, my internet is only 30MB/s, so the download is slow, and my computer is about 7 years old, so it's not so fast
* if you only install the Android SDK for your phone, then it shouldn't take long
* https://developer.android.com/studio/
* looks like you might have to install the studio, or maybe you could select the option to install only the "Android SDK Manager", back when I installed it, years ago, I was able to install only the SDK Manager, but it looks like things have changed, but I'm sure you can figure it out

3. Download and install the latest version of "Java JDK"
* http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html

4. Make sure you download and install the USB Driver for your phone, if you want to be publishing to it, and debugging
* google search it

5. On your phone, you have to enable developer mode,
* googled it, and it's something like going into your settings, and then go into the about, then tapping multiple times on the "Build" information. It should then display a message onscreen saying that "Developer Mode" is enabled
* you should then be able to access the "Developer Mode" options from the main settings menu
* I enabled "USB Debugging" option, and enabled the "Stay Awake" option

6. When you go to build, File > Build Settings, for testing purposes, I have the following settings:
a. Texture Compression: Don't override
b. ETC2 fallback: 32 bit
c. Build System: Internal

e. Run Device: <your device name should be selected>
* if you don't see it, click refresh beside it
* if you still don't see it, make sure that your computer properly detected it, and the drivers were properly installed
* after the drivers were installed, I had to unplug the phone, replug it in, scan for hardware changes from the Computer > Manager > Device Manager
* I had to reboot my computer after the drivers installed
* when windows loaded, then unplug the phone, and re-plug it in to the USB, then finally it recognized the phone

f. Development Build: unchecked
g. Compression Method: default

h.SDKs for App Stores
* Xiaomi Mi Game Center
* when I click to add this, then built, it caused an error that when I googled the error, people said the cause was duplicate files, not knowing which files were dups, I decided to remove the package, and worry about it later



7. Next, I had to set the "Player Settings" from the "Build Settings"

PlayerSettings: 
* Company Name: <set this>
* Product Name: <set this>

Other Settings
* Identification
** Package Name: com.<company name>.<Product Name>
** Version: <set this>

Publish Settings:
* Keystore
** for debugging purposes, the Keystore uses a default one, so this doesn't need to be created at the moment

Build
* build System: Internal
** this should match what you set in the "Build Settings" window > Build System
** I think this changes automatically to match what's in the "Build Settings" window

8. Attempt to Build
* if you are lucky, it will work, but if you are unlucky like me, you might get an error as follows:

CommandInvokationFailure: Failed to sign APK package.
C:\Android\android-sdk\build-tools\28.0.2\apksigner.bat sign --ks "C:\Users\Dieu\.android\debug.keystore" --ks-pass stdin  --ks-key-alias "androiddebugkey" --key-pass stdin  "F:\Unity Game Development\Roll-a-Ball-Extreme\Temp/StagingArea/Package.apk"

stderr[
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
]
stdout[
Error occurred during initialization of VM
Could not reserve enough space for 1048576KB object heap
]

9. I spent all day today (August 24, 2018) searching on google to try figure this out
* well, it was actually 3 or more errors before this, but if you follow my procedure, you should be able to avoid the other errors that I encountered
* so, how did I finally fix this error, I actually didn't find the answer specifically on any post, I ended up investigating the ".bat" file that is used for signing the ".apk" file, in there, I found defaults for the size of the VM that it creates

The ".bat" file is specified in the error message:
C:\Android\android-sdk\build-tools\28.0.2\apksigner.bat

Open it up in your favorite text editor, I used "notepad++",
* the section reads as follows:

REM By default, give apksigner a max heap size of 1 gig and a stack size of 1meg.
rem This can be overridden by using "-JXmx..." and "-JXss..." options below.
set defaultXmx=-Xmx1024M
set defaultXss=-Xss1m

I changed it to:


REM By default, give apksigner a max heap size of 1 gig and a stack size of 1meg.
rem This can be overridden by using "-JXmx..." and "-JXss..." options below.
rem Changed defaultXmx=-Xmx1024M to 512M
set defaultXmx=-Xmx512M
set defaultXss=-Xss1m

Result
When I tried to build again, all errors were gone!! So happy!!

Remember, I'm just starting this journey to learn game programming, so if any of this seems elementary, it's because I've only started 2-3 days ago.

Sorry, no screen captures this time, I only have time enough to write up this story.

Anyways, I hope this helps others out with this error, and with setting Unity up to work in test mode with your device.

If you find this post useful, please leave me a message, it will motivate me to share more often.

Good luck, and happy coding!