Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

9. March 2012

 EDIT: DO not use the included binaries, instead look at the link from the Pang tutorial series to your right!

 

I have gotten a few emails or messages on this topic, enough so that I figure I will put together a post on the subject.  In my PANG! SFML C++ game tutorial, I show how to configure for debug builds but not release.

 

 

So, first and foremost, you are going to need to compile SFML 1.6 for release mode if you don’t already have the release libraries.  You can either download the SFML 1.6  source code here and compile them for release, in either DLL or static mode.  To do so, in Visual Studio 2010 after importing the project ( from SFML-1.6\build\vc2008 ) go ahead and delete the samples folder in the Solution Explorer. Then select the Build Menu, go to the Configuration Manager, then select the build you want to make:

 

Untitled

 

 

You either want to build Release DLL or Release Static, depending on if you are compiling static or dynamic.  If that is completely alien to you what the difference is, dynamic means you will ship the SFML Dll’s with your application, which will contain the SFML related code.  Static on the other hand, will compile all of the SFML related code into your EXE file, making it quite large but easier to distribute.  Either works, but if you ran into the dreaded ATI bug, static fixes it.  On the other hand, if you don’t use all parts of the SFML library, dynamic can be a whole lot smaller.

 

 

If you can’t be bothered building the DLLs, I have compiled them for you.  This archive contains the .lib/dll files for both static and dll versions of SFML compiled for Visual Studio 2010.

 

 

Now that you have the proper lib and dll files, the instructions are basically identical to this part of the tutorial.   The only thing you have to do different is, when in your projects properties before adding libraries, you need to select Release Build.

 

image

 

 

Also, when you specify the library names, you do not include –d at the end.  So for example, instead of adding sfml-system-d.lib, you add sfml-system.lib.  Repeat this for each library.

 

Now you should be able to build the release version of your game without problem.  This again is accomplished using Build->Configuration Manager, like so:

 

image

 

 

Simply switch to release rebuild and done.

Programming

7. March 2012

 

 

Ok, I realize my definition of a week may vary from what you might traditionally expect.  When I started this concept I thought I would find things all the time, and winnowing it down to aPyBook single item would be the biggest challenge!  Hunting down cool things is trickier than I thought!  This “week” was quite easy, it was brought to my attention using the contact form on this site.  If you have something you think other developers ( and developers in training ) would be interested in, send it to me!

 

 

Anyways, enough about my apparent inability to tell time, on to the cool thing.  Are you interested in learning game programming but are intimidated by the gigantic mountain of details ahead of you?  I understand your frustration, it’s an overwhelming subject with so much to learn and so many options available to you, options that you really aren’t well equipped to answer yet.  This is why I put together my beginners guide and you may notice that one of the languages I suggested was Python, although that section was pretty sparse.  Well this item goes a long way towards fixing that.

 

 

Author Albert Sweigart has created not just one, but two Python books about learning to program games using python.  The first book teaches the Python language by building a number of classic “basic” games including Hangman, Tic Tac Toe and Reversi.  Then around chapter 17, he starts to address more advanced games using the popular Pygame library.  Three chapters is far too little time to deal with this subject, and clearly the author agrees, as the entirety of the second book is about using Python with PyGame. 

 

 

The second book creates much more advanced games, while still teaching Python concepts by example.  In this book you create a minesweeper-esque game, a SNAFU/Nibble clone, a 2D Katamari Damacy’ish with squirrels game, a box pusher type game and a handful more.  It is slightly more involved than the first book, but together you should have no problems with it. The author set out to write a book that a 12 year old could understand and I believe he has succeeded.

 

 

At this point you may be wonder why exactly I’ve featured these particular books, there are literally thousands of books out there.  Good question and how is this for an answer…  They are free!  Al has made both books available under the creative commons license completely free, by almost any definition of the word.  You can head over to InventWithPython.com and read either book online, or download them as PDF.  Absolutely no strings attached.

 

 

That said, if you are the type that prefers a physical book in your hands, or you want to reward the author for his hard work, both Invent Your Own Computer Game with Python and Making Games with Python and PyGame are both available on Amazon, for less than 25$.  Looking at the reviews, it seems both of this books accomplished what they set out to do.

 

 

So, if you are just starting out or are picking up the Python language, these two books are a very good place to start.  Really, at a grand total price tag of 0$, what have you got to lose?

Cool Thing of the Week

7. March 2012

 

 

Back in November, Sony rather shockingly announced the closed beta of a C# based developer kit for PlayStation™Certified devices, which include their Xperia Play and moresony-playstation-vita importantly, the Playstation Vita and their as of yet unreleased Playstation tablet.  Then nothing… complete silence.  Rumour suggested a 1000$ price tag, which was reasonable in regards to a console development kit ( and downright cheap if you played Game Dev Story! ), but a rather steep price for your average indie developer.

 

 

Well, good news!  Today Sony announced an open beta in April, and more importantly, a 99$ annual price tag.  Here is the official press release:

 

 

Tokyo, March 7, 2012 – Sony Computer Entertainment Inc. (SCE) today announced that it will release the open beta version of PlayStation®Suite SDK*1 to content developers in April 2012 and the official version later this year. Through the introduction of these SDKs, SCE will offer a more streamlined content development environment for content developers — from large game development companies to small, independent shops — and further expand the world of PlayStation® to open operating system based portable devices.

In November 2011, SCE released the closed beta version of PlayStation®Suite SDK to limited content developers in Japan, United States and the United Kingdom. The upcoming open beta version incorporates their feedback and will dramatically enhance convenience and efficiency of the content development environment. The phased rollout of the open beta version will start in April 2012 free of charge and expand target countries beyond Japan, United States and the United Kingdom. Developers will also be able to conduct performance verification of their content developed with the open beta version on PlayStation®Vita.

SCE will also release the official version of PlayStation®Suite SDK at $99 US annually later this year, allowing content developers to have their content distributed through PlayStation®Store*2 on a commercial basis. Through the official version, content developers will also be able to seamlessly continue to develop content which was created with the open beta or the closed beta versions.

Furthermore, SCE will be adding content for PlayStation®Suite in Japan, United States, Canada, United Kingdom, France, Italy, Germany, Spain, and Australia. The phased rollout of the update will start later this year. The phased rollout will include improving the PlayStation®Suite presence on PlayStation®Store for users who want to enjoy a variety of content with ease and convenience on their PlayStation™Certified devices. SCE will also deliver content created through the official version of PlayStation®Suite SDK after the necessary procedure is completed.

As of March 7, 2012, the line-up of PlayStation™Certified devices include Xperia™ arc, Xperia™ acro, Xperia™ PLAY, Xperia™ acro HD, Xperia™ S, Xperia™ ion*3 from Sony Mobile Communications AB, and "Sony Tablet" S and "Sony Tablet" P from Sony Corporation. SCE will continue to further accelerate the expansion of PlayStation™Certified devices.

Through PlayStation®Suite, SCE will deploy various measures to support content developers in their business, and expand the PlayStation® entertainment experience on an open operating system.

※1 Software Development Kit is a set of development tools and software libraries. Developers are able to obtain this SDK by signing a license agreement with SCE.

※2 Users can download vast digital content including games through PlayStation Store for PS3, PSP, PS Vita and PS Certified devices.

※3 Model name may vary by region. Sales area may vary by model.

 

 

This news isn’t just confined to Sony devices.  Back in February HTC announced that they would be releasing Playstation certified mobile phones.  This may in fact be the movement that finally brings gaming to Android.

 

Truly a great time to be a small budget developer!

News

5. March 2012

 

 

This thread just showed up on reddit, announcing that Unity 3D Basic for Android and iOS are being offered for free until April 8th.  Considering each costs 400$, and how awesome Unity is, this is amazing news if true!

 


Truth is, I go to Unity’s store I get:

image

 

 

Then again, giving away 800$ worth of amazing software for free will cause that, no?  If you haven’t used Unity in the past, now is a very good time to check it out ( well… when the site comes back online ), it is a very impressive game engine.

 

 

So, hopefully this is true, I will keep an eye on the site and hopefully it will come back online.  If this is in fact true, you should jump all over it!  I will update here once I confirm if this is true or not.

 

 

EDIT1:

 

From Unity3d’s twitter feed:

 

image

 

So, unless they got hacked, this deal is looking to be very legit!  I think for a great many people considering targeting iOS or Android, Unity just became a much more likely engine.  Although in the grand scheme of things, 800$ isn’t all that much, it’s enough of a barrier of entry to stop many people.

 

Again, will update once I manage to connect to the store and see it for myself!

 

 

 

EDIT2:  It’s Legit!

image

 

Go get it!

News

28. February 2012

 

 

Picking up where our last section left off, by the end of this chapter you will be able to send a high score across the wire and process it in node.  In order to do this, we need to create a common format both our client and server understand.  In this particular case we are going to use JSON.  If you have done any recent web program, you are probably familiar with JSON already.  Basically JSON is a micro-format designed for transferring data on the web with a lighter footprint than XML.  All told it is a pretty simple format, here is the JSON we are going to use for storing high scores:

 

 

{ "Scores" : [ {"Name" : "Mike", "Score" : 2}, {"Name" :"Bob", "Score" : 14}, {"Name" :"Steve", "Score" : 12}, {"Name" :"John", "Score" : 10}, {"Name" :"Henry", "Score" : 8} ] }

Click here to download Highscores.txt

 

This JSON represents an object named “Scores” composed of an array of 5 objects that in turn are made up of a string field “Name” and a integer field “Score”.  Javascript and JSON go together like peanut butter and jam, but what about C++?  Well, you could encode your data into a string with very little effort ( one of the big advantageous of JSON ), but “little effort” is still effort, and I’m a lazy guy!  Therefore we are going to use an existing library.  I wanted a light weight and extremely simple JSON library, so I went with the aptly named SimpleJSON.  Installation really couldn’t be simple, just add the 4 cpp files ( 2 headers, 2 source ) to your project and you are done.

 

 

Now lets take a look at our SFML client.  It is going to be a simple command line utility for now, from a dos prompt simply pass in the name and high score as parameters, and it will send them across to the node server.  Lets take a look at Scoreboard.cpp:

 

#include "SFML/Network.hpp" #include "JSON.h" #include <iostream> int main(int argc, char* argv[]) { if(argc != 3) { std::cout << "Invalid usage, proper format is player name then score, for example:" << std::endl; std::cout << "Scoreboard \"Player Name\" 42" << std::endl; return -1; } sf::IPAddress ip("127.0.0.1"); sf::SocketUDP socket; sf::Packet packet; JSONObject data; data[L"action"] = new JSONValue(L"AddScore"); data[L"name"] = new JSONValue(std::wstring(argv[1],argv[1] + strlen(argv[1]))); data[L"score"] = new JSONValue(atof(argv[2])); JSONValue * val = new JSONValue(data); data.clear(); std::wstring dataString = val->Stringify(); delete val; std::string notSoWide; notSoWide.assign(dataString.begin(),dataString.end()); packet.Append(notSoWide.c_str(),notSoWide.length()); unsigned short port = 1000; if(socket.Send(packet,ip,port) != sf::Socket::Done) { std::cout << "An error ocurred sending packet" << std::endl; } socket.Close(); return 0; }

Click here to download scoreboard.cpp

 

 

One annoyance of the library I chose for JSON is it works with UTF-8 wide strings, but the string that we send we want encoded as standard ascii, so there is a bit of gunk as we create the JSON object using wide character strings, then after turning it into a JSON string, we encode it back to ascii.  Otherwise the code is quite straight forward.

 

 

First we verify we got the proper number of command line arguments, declare our various SFML and JSON related variables.  We are setting the ip address to 127.0.0.1, which is the loopback address, or the equivalent of saying “this machine”.  Next we build up our JSON string.  If you have worked with XML before, the process will be very familiar. We create a JSONObject named data, which is essentially a map of key value pairs of other JSONValues.  When then populate it with our data, then in turn use it as the parameter in creating a new JSONValue.  All the heavy lifting is done in JSONValue’s constructor.  Stringify() is the method that does the actual re-encoding returning a std::wstring.  Of course, we actually want a std:string, so we create one.  Obviously in time sensitive code, we would alter SimpleJSON to use std::string instead.  Our end result is a JSON string that looks like this:

 

{"action":"AddScore","name":"Bob Dole","score":23}

 

 

Now that we have our data in JSON encoded string format, it’s time to send it.  We simply append our string data to our packet and send it using our Socket.  If an error occurs, report it.  Otherwise, we are done, close our Socket and exit.  If you strip away all the wide character string annoyances, the process is actually quite straight forward.

 

 

Now lets take a look at the Node side of things.  The code is fairly long, so instead of walking through it I have simply commented it.  If you have any questions not covered by the comments, fire away.  So here is the contents of Server.js

 

var dgram = require('dgram'), fileSystem = require('fs'), highScores, server; //Load high scores from file fileSystem.readFile("HighScores.txt", 'utf8', function(err,data){ if(err){ //Error occurred loading file, spit out error message then die console.log("Error occurred loading file"); process.exit(); } console.log("Loading high scores from file"); try{ // use JSON to turn file contents back into a Javascript array object highScores = JSON.parse(data); }catch(e) { // Exception occurred parsing file contents as JSON, error out and die. console.log("Exception occured parsing data"); process.exit(); } // Now sort the high scores by score, high to low highScores.Scores.sort(function(a,b){ return b.Score - a.Score; }); // Display the sorted high scores to the console console.log(highScores); }); //Alternative way to read file in NodeJS //file.on("error",function(exception){ // process.exit(); // } //); //file.on("data",function(data){ // fileData = data; // } //); //file.on("close",function(){ // highScores = JSON.parse(fileData); //}); //Create a UDP socket server = dgram.createSocket('udp4'); console.log("Socket created"); // Add a handler for incoming traffic on the socket. This will be called each time something connects to the socket server.on("message",function (msg,rinfo) { //console.log(parseInt(msg).toString()); console.log(rinfo); // SFML sends two packets, one with the size of the following packet ( as a 4 byte number ) // We don't need it, so as a crude-hack, we ignore any 4 byte packets if(rinfo.size != 4) { console.log("Received message:" + msg.toString()); // Socket data comes in as a JSON encoded array of objects, turn back into a JS object var jsonData,i; try{ jsonData = JSON.parse(msg); } catch( exception ) { console.log("Invalid JSON request received"); return; // Non lethal error, just stop processing packet } // The action parameter determines what you should do with this packet switch(jsonData.action) { // action==AddScore, add the score to the highscore array if it's higher than an existing score case "AddScore": console.log("AddScore called\n"); // Make sure highscore has been initialize... order can be a weird thing in node if(highScores != undefined){ // Loop through current highScores ( which should be sorted ) // and insert score if a lower match found for(i=0;i < highScores.Scores.length;++i) { if(highScores.Scores[i].Score < jsonData.score){ highScores.Scores.splice(i,0,{"Name" : jsonData.name, "Score" : jsonData.score}); console.log("Inserted highscore by: " + jsonData.name); break; // match found, stop looping } } } // Display newly created highscore array console.log(highScores.Scores); break; } } // // }); // Called when socket starts listening for packets. besides logging, currently serves no purpose server.on("listening", function () { var address = server.address(); console.log("server listening " + address.address + ":" + address.port); }); // Finally, bind the server to port 1000. 1000 was randomly chosen. Think of this as saying GO! // Now we are listening for UDP connections on port 1000 server.bind(1000);

Click here to download server.js

 

 

Now start the server at the command line ( node server.js ) and run the client from a different command line.  It should look like this:

 

image

 

 

As you can see, we are successfully sending data from SFML over a socket to our node based server.  In the next part, we will look at sending data the other way.

 

 

You can download the complete project right here.  The scripts are in a sub-folder named NodeJS.

 

 

Click for part 3

Programming ,

Month List

Popular Comments