Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon Join the GFS Discord Server!
31. May 2012



Alright I admit it, something shiny and new came along and of course I am attracted to it!  As I mentioned a few days back, the Cocos2d-x team released Cocos2d-html, an HTML5 port of theCocos2dHTML5 popular Cocos2D iPhone game library.


I have never worked with a Cocos2D library yet, although Sony’s GameEngine2D is based heavily on it.  So I jumped in to the HTML5 version and I have to say I am extremely impressed so far.  Therefore I am going to do a (simple?) tutorial series on using Cocos2D-x to create HTML5 games.  I am not sure exactly how much detail I am going into but it should be kind of fun.  Expect a setup and Hello World tutorial post anytime.


Don’t worry though, I am still working on new PlayStation Suite tutorials, still intend to do an HTML5/RPG tutorial ( although whether I use HTML5, or a library like Cocos2D-x is up in the air, working with a library is so much nicer! ) in the near future and yes, I am going to finish my C++ game tutorial too.  What can I say, I love juggling projects.


So, if you are interested in developing 2D games targeting HTML5 web browsers be sure to keep an eye on this space, something will be coming soon!


If on the other hand, you are a Cocos2D veteran and you seem me doing something stupid, please let me know!




30. May 2012


There was an interesting ( to me anyways… ) topic on Reddit today about making games that are accessible to the blind or visual impaired.  After thinking about this for a little bit, I though that there might be a remarkably easy way to add text to speech to a console based game.  Turns out I was correct.



The following is a C# app that makes heavy use of the .NET System.Speech libraries, however it does appear to be available in Mono, so it should work across platforms.


In the end the process is remarkably simple, all I am doing is redirecting Console.Out ( StdOut ) to my custom class, which converts the text to speech.


Let’s take a look, this code is across two classes.  One is our exceedingly simple game:


using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AudibleTextAdventure { class Program { private static StdoutToSpeech speechOut; static void Main(string[] args) { speechOut = new StdoutToSpeech(); Console.SetOut(speechOut); Console.WriteLine("You are standing in an open field west of a white house, with a boarded front door."); Console.WriteLine("There is a small mailbox here."); bool done = false; while (!done) { Console.Clear(); Console.WriteLine("What would you like to do?"); string currentCommandString = Console.ReadLine().ToLower(); string [] tokens = currentCommandString.Split(new char[] { ' ' }); string currentCommand = tokens.First(); switch (currentCommand) { case "volume": { if (tokens.Length > 1) { if(tokens[1].ToLower() == "up") speechOut.VolumeUp(); if(tokens[1].ToLower() == "down") speechOut.VolumeDown(); } break; } case "quit": done = true; Console.WriteLine("Thank you for playing, Goodbye"); break; case "help": Console.WriteLine("Sorry, you are beyond help"); break; case "changevoice": speechOut.NextVoice(); break; default: Console.WriteLine("I don't know the work \"" + currentCommand + "\""); break; } } } } }



Most of that code is the skeleton of our “game”.  The majority is just getting and displaying strings as well as parsing and handling the commands our game accepts. The only lines of any real consequence here are:

speechOut = new StdoutToSpeech(); Console.SetOut(speechOut);


Here we declare our StdoutToSpeech object we are about to define in a second, and replace the standard output stream with it.  Now lets look at StdoutToSpeech:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Speech; using System.Media; namespace AudibleTextAdventure { class StdoutToSpeech : System.IO.TextWriter { static System.Speech.Synthesis.SpeechSynthesizer synthesizer; static SoundPlayer soundPlayer; static System.IO.TextWriter origOut; static int currentVoice = 0; static List<System.Speech.Synthesis.InstalledVoice> voices; public StdoutToSpeech() { // Grab a reference to Stdout before it's overridden origOut = Console.Out; synthesizer = new System.Speech.Synthesis.SpeechSynthesizer(); // Will bork if no voices found voices = synthesizer.GetInstalledVoices().ToList(); synthesizer.SelectVoice(voices.First().VoiceInfo.Name); // Slow it down a bit synthesizer.Rate = -1; synthesizer.Volume = 5; soundPlayer = new SoundPlayer(); } public override void WriteLine(string value) { // We still want text to show... origOut.WriteLine(value); using (System.IO.MemoryStream mem = new System.IO.MemoryStream()) { synthesizer.SetOutputToWaveStream(mem); synthesizer.Speak(value); soundPlayer.Stream = mem; soundPlayer.Stream.Position = 0; soundPlayer.PlaySync(); } } public void VolumeUp() { if (synthesizer.Volume < 10) { synthesizer.Volume++; this.WriteLine("Volume increased"); } } public void VolumeDown() { if (synthesizer.Volume > 0) { synthesizer.Volume--; this.WriteLine("Volume reduced"); } } public void NextVoice() { currentVoice++; if (currentVoice >= voices.Count) currentVoice = 0; else { synthesizer.SelectVoice(voices[currentVoice].VoiceInfo.Name); this.WriteLine("Voice changed"); } } public override Encoding Encoding { get { throw new Exception("If you are trying to use this as text, you are in for a world of hurt!"); } } } }


In our constructor we create our System.Speech.Sythensis.SpeechSynthesizer, set a voice, default speed and volume for it.  We also instantiate our SoundPlayer which is going to actually play the sound file our synthesizer um… synthesizes.


The key to this class is that it inherits from System.IO.TextWriter, this is the only type that we can set standard out to.  Our class must implement the Encoding:Get method, which if anyone actually called would cause all kinds of problems, so we throw an Exception if it is actually called. In the constructor we take a snapshot of the original standard out, so we will still be able to print to text.


Otherwise most of the work happens in our WriteLine overload.  First we print out to the original standard out, otherwise our command prompt would become audio only!  Next we create our memory stream that our synthesizer is going to record to.  We then render whatever speech was printed via a Console.WriteLine() call, set it as the active stream and play it using our soundPlayer.  We using PlaySync() to make sure it finished playing before continuing execution.  You could use Play(), but it would only render the most recent sentence if a couple lines where written at once.   Also note, we only overrode WriteLine(string), so if you do Console.Write, Console.WriteLine(char[]) or any other version, nothing will happen.  If you want to support more versions, you need to implement.


Otherwise the rest of the code provides a simple interface for increasing and decreasing volume, as well as changing between voices.  Keep in mind though, if you are using Vista or Windows 7, you probably only have on voice installed.  You can however add additional voices ( including different languages ), I download one from here for example ( copy the dlls to your debug folder if you get an error ).



Now when you run the application, you can use the following commands:

quit – exits the “game”

volume up – increases the voices volume

volume down – decreases the voices volume

help – displays a help string

changevoice – changes to the next installed voice, if you have any.



Obviously in a real game you would do substantially more.  In a real game you would also add a great deal more error checking too, as this is just a proof of concept I slapped together!  Obviously use at your own risk, as I offer no warranty.  Then again, I never offer a warranty…



And here it is in action:

Text to speech adventure in action


30. May 2012



As some of you may have noticed earlier today, the site was displaying a configuration related error message.  I am frankly a bit confused at what the cause was, as when I modified my web.config to show me the error, it went away!


Also, if you’ve gone to use the contact me form, you may have noticed I added a captcha to the form.  I hate to do this, as I hate captcha’s.  Unfortunately I have a script kiddy attacking the site as a result of my comments about C++.  ( sigh )  His/her attack script was resulting in an annoying number of emails being generated and thus… the captcha.


As a result of all of this, I’ve decided to take today to apply all the outstanding updates.  This unfortunately means a bit more downtime.  So if you have a bit more trouble today accessing the site, this is why.  Hopefully when I am done we will have an all around happier, more secure and quick


Again, sorry for the outages.



EDIT:  Had another outage, so I did a bit of investigating and found out why.  Apparently our intrepid hacker friend had two other friends who more or less have been slamming the server all day with hacking scripts.  GameFromScratch is actually hosted on pretty solid servers with a good sized pipe so we can survive this.


What we cannot survive however is running out of disk space.




Apparently the hack attempts grew the log files quite a bit which was resulting in running out of disk space causing the error.  The log files weren’t actually filling up the space ( that was my screw up, I automatically back up a database daily… didn’t realize that database was up to 2GB in size! So I pruned a few dozen 2GB backup files and now a 200mb log file wont do a thing), but they illustrated that I was running out of disk.


That said, this was just slapping a band-aid over the problem, so I’ve gone one step further.  First off, I implemented firewall level blocking, so all of these addresses are now blocked.  Next I put in intrusion detection that will automatically reject people making too many connections.  The threshold is pretty high, you have to try pretty hard to trip it if you aren’t a bot, but if you receive a 403 message, this is why.


Hopefully this doesn’t cause any of you problems.  If you do have connection problems to this site, please let me know!


It’s a shame I have to do this stuff at all.  Some people take their programming languages FAR too seriously.

29. May 2012



Oh joy of joys.  Tonight I get some nasty work off my plate and decide to wind down for some Diablo 3 action.  Initially I start encountering server problems and a quick check on their server status page shows that their servers are down.  Great.


So I let about an hour go by.  This being Diablo, I of course have to fight through a series of Error 37’s, but I eventually get logged in.


To be greeted by the message:


A new patch for Diablo III is available. The game will now close and apply the patch automatically. You will be able to continue playing after the patch has finished installing.


Oh joy, I love forced patching of my single player games…


Click OK and…




Lovely, “Diablo III has stopped working”.  Exactly what I wanted to see.  Then followed by this lovely screen:




“Diablo III is already running”.



From my outside perspective, it appears the game patcher is trying to restart the game to apply a patch, but the game isn’t exiting, causing the version that is going to do that patching to die a horrible APPCRASH death.


EDIT ( Fix details ):

Crash is being caused by having a client on a server at a different patch level.  For example, I ran the UK installer apparently, but I am playing in the America regions.  The patch has been deployed to the America’s but not the UK.  So when I log in to the American server, its sending me to the UK server to patch, and there is no patch available, so it crashes. You can check your install version by going to C:\Program Files (x86)\Diablo III\Data_D3\PC\MPQs.  If the folder is enGB and you are logging in to the American server, this is why you are crashing.

You will either have to wait for Blizzard to push the patch out to the UK, or re-download the game with the US client.  If you are constantly being logged in to the wrong servers, this is also probably the reason and solution.

Seriously Blizzard, amateur hour. Sad smile


And again… this is on my SINGLE PLAYER game, that I again cannot play online because of the stupid auction house, that I am never EVER going to use.


Let’s just say, as a non-WoW player, Blizzard to me is just another developer, one who is losing all of my goodwill fast!  For the record, I currently have no work around, except that is to wait for Blizzard to fix their damned game. Sad smile


If I do come across a fix for the Diablo 3 patching loop of death ™, I will post it here.


Oh, and Blizzard, CACHE MY DAMNED PASSWORD!!!  I hate entering it again and again and again while trying to get past the Error 37 messages. 



EDIT:  Well it appears when I bought it from, because I speak Queen’s English ( I am Canadian ), it gave me the enGB client!  This may be contributing to the crash, but it’s going to really annoy me if I have to download the entire thing again just to fix this!  I currently cannot select an English options other than enGB.


If I set my region to Europe, it doesn’t try to patch and the crash doesn’t occur!


Log in to and here is my download setting:




The client they sent me is English(EU) this results in your patch server being So if I want to stop being sent to the UK servers, it appears I need to download the client all over again, this time with English (US) selected. You can check yourself by opening your .agent.db file, in my case located at C:\Program Files (x86)\Diablo III.  Since it’s name starts with a “.”, you may need to set “Show Hidden Files” in Explorer to true to be able to see it.


{ "uid" : "diablo3_engb", "config" : { "expansion_level" : 0.000000, "last_played" : 0.000000, "update_progress" : 0.000000, "ptr" : false, "beta" : false, "supports_multibox" : false, "fullpath_hash" : false, "archive_override_subpath" : "", "data_dir" : "Data_D3/PC/MPQs/", "switcher" : false, "use_sparse" : false, "patch_url" : "", "priority_file_layout" : "Retail", "product" : "D3", "updater_product" : "d3_patch", "update_identifier" : "d3-update-", "update_method" : "patch on demand", "update_regex" : "(?P<prefix>d3-update-(?P<dataset>\\w+))-(?P<build>\\d+)\\.mpq$", "torrent_file_path" : "Diablo III.tfil", "manifest_file_path" : "Diablo III.mfil", "priority_file_path" : "Diablo III.pfil", "binary_version_path" : "Diablo III.exe", "binary_launch_path" : "Diablo III.exe", "binary_launch_path64" : "", "run64bit" : false, "uninstall_path" : "C:\\Program Files (x86)\\Common Files\\Blizzard Entertainment\\Diablo III\\Uninstall.exe", "installed_locales" : [ "enGB" ], "display_locales" : [ "enGB", "esMX", "ptBR", "koKR", "zhTW", "deDE", "esES", "frFR", "itIT", "plPL", "ruRU" ], "launch_arguments" : [ "-launch", "-uid", "diablo3_engb" ], "preinstalled" : true } }



As you can tell from patch_url, it is setting me to international servers and launch_arguments.



I doubt this is the problem, but this would be why Diablo 3 keeps trying to send me to the European servers!


If you are finding Diablo 3 keeps sending you to the wrong continent, log in to, check your client and see what language it is set to.  Hopefully I will find a solution that doesn’t require re-downloading everything.

29. May 2012


This is one of those libraries I really have been meaning to check out.  Every time I turn around it seems like it’s been ported to another platform and today is no different!cocos2dbanner  Cocos2D can now target HTML5.



In the developers own words:


We are happy to announce that Cocos2d-html5 alpha is released!

This is the first version of Cocos2d-html5. Most of functionality and test cases from Cocos2d-X are implemented in Cocos2d-html5. Currently, Cocos2d-html5 utilizes canvas for rendering, the API is almost the same as Cocos2d-X and Cocos2d-iPhone. High level API will be wrapped in next phase, which will offer nicer interface for Javascript programmers and will also be compatible with the javascript binding of Cocos2d-x & Cocos2d-iPhone.

Cocos2d-html5 has two menu implementations. One is DOM menu, and the other one is canvas menu. DOM menu will run more efficiently, but the drawback is that all menu items will always above the canvas.

Test cases has being tested and works as expected on

  • Chrome 16 & 18,
  • Safari 5.1,
  • IE 9 & 10
  • Firefox 12.0.


You can run through all of the demos in the browser using the above link, or check out the getting started guide here.  At this point I think Cocos2D is basically available on every platform for every language short of BASIC for the Amstrad, but I am sure there is a port in the works!


I really have to check this library out one of these days.


See More Tutorials on!

Month List