Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon
16. October 2012

 

I recently read this ( very good ) blog post documenting the process of developing and publishing the game Pumped BMX and was struck by one thing.  I really really liked the font he used on his site, it was clean but not gimmicky.

 

It turns out the font is Open Sans, created by Google.  I have decided to adopt it on GameFromScratch.com.  With the recent increase of page width I also decided to increase the font size from 12 to 14pt.

 

Here are before and after results:

image

 

What do you think?  Like it better the new way, or prefer the old font?  All told they are both fairly similar fonts, so it’s not a very massive change.

Totally Off Topic


14. October 2012

 

I don’t think there are many people out there that would argue that JavaScript isn’t an important language.  It certainly is, and with the recent death of Flash and Silverlight in the browser and the hype behind HTML5, to say nothing of Node, it is actually getting more popular

 

I also don’t think there are many people out there that would argue that JavaScript is a heavily broken language too.  As systems written in JavaScript become larger and more complex, the language flaws become more and more pronounced.  Just as C++ ultimately came about from C’s (arguable by some) inability to deal with complexity, a number of companies and groups are looking at possible successors to JavaScript.  Generally all of these languages are backward compatible with JavaScript in some form.  Let’s take a look at the contenders for the short term future of JavaScript.

 

 

ECMAScript 6 AKA Harmony AKA ES.next

 

When talking about the future of JavaScript, the most logical place to start is … well, the future of JavaScript, the next version.  The spec is a work in progress and you can read it here, the most recent revision as of writing (September 27th, 2012).  It would seem obvious that the next version of JavaScript would be ECMAScript 6, but don’t bet the farm just yet.  After all, ECMAScript 6 is effectively a scaled back version of ECMAScript 4, while ECMAScript 5 (the JavaScript version in common usage today), is essentially a fork of ECMAScript 3.  Firefox and Chrome already support bits of ECMAScript 6, so it’s future is quite bright, but by no means are things certain.  Plus there is no way of knowing how long until ECMAScript 6 is supported enough to actually make it useful.  For an idea of where ECMAScript support in various browsers is, check out this handy table.

 

This has opened the door to a number of alternatives, many are languages that compile down to JavaScript making them useful today. Others (like Dart) compile down to JavaScript as a fallback, but perform better in their native environment.

 

 

The 900lb gorillas.

 

Two of the companies are very interested in the future of JavaScript are Google and Microsoft.  Each has created a language they hope will be the future of JavaScript, Dart and TypeScript respectively.

 

This interview between Anders Hejlsberg ( Microsoft, creator of Delphi, C# and now TypeScript ) and Lars Bak ( Google, creator of V8 JavaScript engine and Dart ) is very good summary.  It allows each developer to describe their opinions of the existing problems with JavaScript ( on which they largely agree ) and describe the strengths of each of their companies offerings.

 

Anders Heljsberg & Lars Bak on TypeScript/Dart and the problems with JavaScript today

 

 

Google Dart

 

http://code.google.com/p/dart/ or http://www.dartlang.org/

image

 

In Their Words:

Why Dart?

At Google we've written our share of web apps, and we've tried in many ways to make improvements to that development process, short of introducing a new language. Now we think it's time to take that leap. We designed Dart to be easy to write development tools for, well-suited to modern app development, and capable of high-performance implementations.

 

Dynamic or Static Typed?

Dynamic

 

Key language features

Compiles down to JavaScript, or to the Dart VM ( which is currently only available in Chrome ).  Code running in the Dart VM will perform better.

Language is basically JavaScript with prototypes removed and classes added.  They’ve added lexical closures, sane this management, optional static types, named parameters, cleaner event and DOM programming and more.

The language also comes with an IDE, the Dart Editor, which is a mash-up of Eclipse, Chromium and the DartVM.  For those like me that prefer WebStorm/IntelliJ over Eclipse, they also have a plugin available.  There used to be a cloud based editor, but it appears to have been retired.

 

My 2 cents

Dart technically solves most of the problems with JavaScript and is compatible with existing JavaScript.  That said, I checked out Dart shortly after it was released, then again 6 months later and as usual, Google’s developer support stunk.  They just don’t put the extra effort in to making the experience easy on developers ( at the time, the Windows build didn’t work, you need to compile everything yourself, etc… this lack of polish is just as common with other Google developer tools such as GWT, NativeClient even Android), but the package seems to be improved quite a bit.  Just a warning though, if you aren’t experienced with Google developer support, be prepared for a ton of frustrations if you run in to any problems.

Probably the biggest flaw with Dart is going to be the lack of adoption.  Dart compiles to JavaScript as a fall back, but the VM is obviously the preferred platform.  Google announced their intention of submitting Dart to a standards body, but do you see Microsoft or Mozilla adopting Dart?  Yeah, me neither.  That said, Chrome is getting a pretty big install base.

My biggest problems are the above mentioned Google support, and their tendency to kill off projects at the drop of a hat lately. 

 

 

Microsoft TypeScript

 

http://www.typescriptlang.org/

 

image

In Their Words:

Why TypeScript?

TypeScript is a language for application-scale JavaScript development. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open Source.

Dynamic or Static Typed?

Static

 

Key language features

TypeScript is compiled down to JavaScript.

Language allows you to add static types to JavaScript, allowing you to catch type errors during the compilation process ( although the compilation will still generate a JS file ).  Allows you to mix and match TypeScript and JavaScript in existing files.  Adds new constructs to the language such as classes, interfaces and modules.

IDE support is available in the form of a Visual Studio 2012 plugin, as well as plugins for Sublime Text, Vi and Emacs.  They also have Node support out of the box and you can download TypeScript using NPM.

 

My 2 cents

I will admit, I am a bit of a Anders fanboy, so that has gotten me excited about this language.  Language design is all about pragmatic choices, and Anders just seems to pick the right compromises.

At the end of the day, TypeScript is less of a gamble than Dart, and this has it’s advantages and disadvantages.  As Lars said in that video above, TypeScript is “the safe bet” and that is a pretty apt description.  It is a layer on top of JavaScript and nothing more, in many ways it is quite similar to CoffeeScript.  In the end though, TypeScript is probably the one that will best integrate with existing Javascript and given the massive variety of existing code, that is probably a pretty big advantage.  At the end of the day though, TypeScript is ends up being JavaScript, so don’t expect any performance improvements.

The tooling support is shockingly not Microsoft.  Would you have ever expected Vi and Emacs support from day 1?  What about Node support?  There is a noted lack of documentation at this point, which is shocking for a Microsoft product.  They do however have a nifty Playground/Tutorial environment that allows you to type TypeScript and see the generated JavaScript.  Sadly for now, comments and whitespaces are mangled as part of the process, although this is a temporary flaw.

 

 

CoffeeScript

http://coffeescript.org/

 

In Their Words:

CoffeeScript is a little language that compiles into JavaScript. Underneath all those awkward braces and semicolons, JavaScript has alwaysimage had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

The golden rule of CoffeeScript is: "It's just JavaScript". The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime

 

Dynamic or Static Typed?

Dynamic

 

Key Language Features

Coffeescript is a whitespace ( as opposed to curly brace ) based language that compiles down to JavaScript.  It is certainly the elder statements of the group and has been around for a number of years.

Coffeescript provides a number of features to JavaScript including a class system, lexical scoping, splats (…) for variable arguments, array slicing and more.  Additionally it provides a layer of syntactical sugar over some of the JavaScript warts such as is instead of === or unless as the inverse of if.

Coffeescript also offers impressive tooling support.  Like TypeScript, it is available as a Node utility, making installation via NPM trivial.  Most IDEs support Coffeescript ( IntelliJ, Eclipse, WebStorm, Netbeans, Sublime Text, etc ) out of the box.

 

My 2 cents

I only gave CoffeeScript the smallest of evaluations and that was a few years back.  You see, I have an irrational hatred of whitespace based languages.  What I found most irksome ( and TypeScript fixed this ), is that it’s a language on-top of JavaScript, not within Javascript.  So you had to program things the Coffeescript way, then compile it to JavaScript.  Coffeescript felt like a completely different language than JavaScript, while neither Dart nor TypeScript gave me that impression.  Mostly though, I never got over my hatred of whitespace based languages.

All that said, CoffeeScript solved many of the problems that Dart and TypeScript are setting out to solve, and it solved them years ago.  It’s by far the most mature and as a result had the most time to iron out the kinks.

 

 

Other Options

 

Dart, TypeScript and CoffeeScript are by no means the only options when it comes to more programmer friendly JavaScript programming languages, but they are the three that are closest to JavaScript itself.  The following are a selection of other languages that will compile to JavaScript.

 

 

GWT – Google Web Toolkit

 

https://developers.google.com/web-toolkit/

Google Web Toolkit (GWT) is a development toolkit for building and optimizing complex browser-based applications. GWT is used by many products atimage Google, including Google AdWords and Orkut. It's open source, completely free, and used by thousands of developers around the world.

Basically GTW is a Java –> JavaScript compiler.  That is over generalizing, but basically you write your code using a subset of libraries in the Java language, and it is compiled down to JavaScript.  Or a bit of mix and match, with Java running on the server and JavaScript on the client.  The programmer never really works in JavaScript when working with GWT.

 

As is pretty typical with Google projects, IDE support is mostly Eclipse based.  There are a few published books available for GWT.  GWT has been around for quite a while and integrates nicely with Google App Engine.  That said, if you aren’t a Java developer, GWT really isn’t for you.

 

 

 

Haxe

 

http://haxe.org/

Haxe is a powerful modern language with many compelling features. It is aimed at giving developers a tool to create websites & applications using aimage single unified programming language. Whether you use Haxe for its cross-platform features, or focus on a single platform, there are many reasons to adopt it.

Haxe is a language that allows you to compile down to JavaScript, Flash, NekoVM, PHP, C++, C# and Java.  It provides a standard language and library that compiles down to the mentioned languages, while filling in the missing pieces of each language, such as packages and typing for JavaScript, reflection for C++, etc.  The Haxe language itself is derived from ActionScript 3, which itself is a ECMAScript language. Haxe has pretty good IDE support. Haxe also has a few published books which is always handy.

 

I’ve not yet used Haxe, mostly because I have no prior ActionScript experience and because I never really had the time to look into it further. That said, HaxeNME, which is a gaming library targeting web, mobile and desktop certainly has piqued my interests.

 

 

 

Other other options…

 

This doesn’t even come close to listing all of the languages that compile to JavaScript, for a more complete list see this.  This does however cover the major players, at least as I see them.  If you think I made a major omission or mistake in this list, please let me know!

 

JavaScript is becoming more important and JavaScript programs are becoming more complex.  The language does have a number of flaws, but fortunately there are a number of options to help you cope, at least until ECMAScript 6 arrives.

General Programming


12. October 2012

 

I have been following RIM’s Gameplay 3d engine for some time now and they have been improving it at a pretty impressive rate.  Well, they just announced the release of version 1.5.  If you’ve never heard of Gameplay, it is a cross platform mobile game development kit written in C++, but scriptable in Lua.

 

Gameplay3d currently supports the following targets:

  • BlackBerry 10 and PlayBook 2.0 (using BlackBerry Native SDK)
  • Apple iOS 5.1 (using Apple XCode 4.3.2)
  • Google Android 2.3+ (using Google Android NDK, SDK API level 9+)

 

And can be developed using the following platforms/compilers:

  • Microsoft Windows 7 (using Microsoft Visual Studio 2010)
  • Apple MacOS X (using Apple XCode 4.3.2)
  • Linux (using CMake or CodeBlocks 10)

 

As to what’s new in 1.5:

  • Linux support. (tested on Ubuntu 12)
  • CMake support for makefile generation for Linux.
  • CodeBlocks 10 IDE support for Linux.
  • Gamepad controllers support for desktops.
  • Touch gesture support for tap, swipe and pinch.
  • Vehicle phyics support via new PhysicsVehicle and PhysicsVehicleWheel classes.
  • Adds new racer sample (sample06-racer).
  • Adds gameplay-tests project as a test app for various basic engine features with some initial tests.
  • Adds support for Scene files for wildcard identifiers.
  • Adds Visual Studio Plug-in support for BlackBerry PlayBook and BlackBerry 10.
  • Adds configurable multi-sampling anti-aliasing support.
  • Adds updates to latest FBX SDK 2013.3.
  • Adds file formats documenation for game.config .scene, .material, .animation, .physics, .particle
  • Adds Game/Platform::canExit for testing device capabilities to quit. (only ios)
  • Web community forums at http://www.gameplay3d.org/forums.
  • Changed keyTimes from unsigned long[] to unsigned int[]. (breaks compat. in AnimationTarget and Animation::Channel)
  • Fixed inconsistencies from Bundle::getObjectID() to Bundle::getObjectId() (breaks compat. in Bundle)
  • Fixes the texture coordinates of Mesh::createQuad(float x, float y, float width, float height).
  • Fixes line-wise distortion when loading RGB png's into texture that are non-power of two.
  • Fixes inconsitencies in createXXXX methods. (breaks compat. in Scene)
  • Fixes Rectanngle::contains.
  • Fixes Lua print logging.
  • Fixes Lua errors to be treated as runtime warnings.
  • Fixes setVertexData to pointers instead of constant data.
  • Fixed AudioSource so that it doesn't loop by default.
  • Fixes minor UI scrolling issues.

 

And what’s in the works:

  • AI Pathfinding
  • Terrain and Water
  • Asset Pipeline improvements

 

You can download Gameplay on Github.  For a quick guide on getting started check here, it’s a bit old but should still be mostly relevant.

 

Good work Gameplay team!

News


12. October 2012

 

If you followed my Moai tutorial series, you may recall in this post I mentioned that Android keyboard support currently didn’t exist, although there is an effort underway to fix that.  Well, a user over on the Moai forums got sick of waiting and implemented a soft keyboard using MoaiGui, which I covered in this post.

 

It is written as a Lua module and the only dependency is you need to pass in your Moaigui object.  Here is the code:

--utility function
function distance ( x1, y1, x2, y2 )
        return math.sqrt ((( x2 - x1 ) ^ 2 ) + (( y2 - y1 ) ^ 2 ))
end

k = {}

local kboard = nil
local keysWide = 1
local keySize = 5
local boardHeight = keySize
local left = 50 - keySize/2
local top = 100
local xpos = left
local ypos = top
local rowCount = 0
local speed = 1000
local textbox = nil

--release all gui objects
k.destroyKeyboard = function (self, gui)
        if kboard ~= nil then
                for k, v in pairs(kboard) do
                        gui:destroyWindow(v)
                end
                kboard = nil
        end
end

--setup a new keyboard, starting with only 1 row
k.createKeyboard = function (self, gui, charsWide)
        if kboard ~= nil then destroyKeyboard(gui) end
        kboard = {}
        keysWide = charsWide
        boardHeight = keySize
        left = 50 - keySize*charsWide/2
        xpos = left
        top = 100
        ypos = top
        rowCount = 0
end

 

local function keyClick(event, data)
        --give focus to selected textbox so that it receives the keypress
        if textbox ~= nil then data.g:setFocus(textbox) end
        --pass keypress to gui
        data.g:injectKeyDown(data.character)
        data.g:injectKeyUp(data.character)
end

 

k.addKey = function (self, gui, char)
        if kboard == nil then return end
        --empty string indicates skipping a key slot
        if char ~= "" then
                kboard[char] = gui:createButton()
                kboard[char]:setPos(xpos, ypos)
                kboard[char]:setDim(keySize, keySize)
                kboard[char]:setText(char)
                data = {}

                data.g = gui
                if char == "<" then
                        data.character = 8 --backspace
                else
                        data.character = string.byte(char) --ascii value of character
                end

                kboard[char]:registerEventHandler(kboard[char].EVENT_BUTTON_CLICK, nil, keyClick, data)
        end
        --increment to next key in row
        rowCount = rowCount + 1
        xpos = xpos + keySize
        if rowCount >= keysWide then
                --new row
                xpos = left
                ypos = ypos + keySize
                boardHeight = boardHeight + keySize
                rowCount = 0
        end
end

 

--moves the key to its place at the bottom of the screen (or off the screen if show=false).
--NOTE: only returns once the move has finished
local function moveKey(key, show)
        local x, y = key:getPos()
        --move onto the screen
        local newy = y - boardHeight
        --move off the screen
        if not show then newy = y + boardHeight end
        --not really the best way of getting the target location, but the easiest/quickest solution
        key:setPos(x, newy)
        local tx, ty = key._rootProp:getLoc()
        key:setPos(x,y)
        --calculate a travel time relevant to the distance being traveled
        local travelTime = distance(x, y, x, newy) / speed

        MOAIThread.blockOnAction(key._rootProp:seekLoc(tx, ty, travelTime, MOAIEaseType.LINEAR))
        --the seekLoc only moves the prop, the prop container is not aware of the move, so tell it.
        key:setPos(x, newy)
end

 

--moves all keys to the desired location
k.showKeyboard = function (self, gui, show)
        if kboard == nil then return end
        --only need to pass in show when you want to hide the keyboard
        if show == nil then show = true end
        for k, v in pairs(kboard) do
                --move keys in separate threads
                MOAIThread.new():run(moveKey, v, show)
        end
end

 

k.hideKeyboard = function (self, gui)
        self:showKeyboard(gui, false)
end

k.setTextbox = function(self, tbox)
        textbox = tbox
end

return k

 

 

And here is some code demonstrating the keyboard in action:

 

local kb = require "keyboard"

kb:createKeyboard(gui, 11)
keys = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "<",
        "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "",
        "", "a", "s", "d", "f", "g", "h", "j", "k", "l",  "",
        "", "", "z", "x", "c", "v", "b", "n", "m"}
for k, v in pairs(keys) do
        kb:addKey(gui, v)
end

kb:showKeyboard(gui)

local editBox = nil
local function handleEditBoxGainFocus(self, event)
        self._cursorPos = #self._internalText + 1
        self:_addCursor()
        kb:setTextbox(editBox)
        return self:_baseHandleGainFocus(event)
end

editBox = gui:createEditBox()
editBox :setPos(40, 30)
editBox :setDim(20, 5)
editBox :setText("")
editBox ._onHandleGainFocus = handleEditBoxGainFocus

 

 

None of this code is mine, all of the credit goes to lancew over on the Moai forums.  The only thing I have done is slightly changed the formatting to make it a bit more legible. You can read the original thread right here.

 

Great work Lance!

Programming


12. October 2012

Just a heads up, this post has absolutely nothing to do with game development.  It was a little annoyance I ran into today that had a completely unintuitive answer.  I post here so that, thanks to the power of Google, others may learn from my frustration.

 

I have a laptop that is for portability, the one I use when I am out and about ( which is more often then not ), but when I am home, my wife often makes use of it.  For debugging reasons, I hate having unknown processes running in the background, so I always log her account off the next time I log in.  I have done it the same way for years, open Task Manager ( CTRL+SHIFT+ESC ), go to the Users tab, right click the user name and select log off.  As the title suggests, today things didn’t quite work out and I received the error “User username (SessionId=1) could not be logged off.  Access denied.”.  First off, my wife’s name isn’t Bob in case you are wondering.

 

Second, the fix is really easy, just completely confusing why it is a fix at all!

In Task Manager, switch over to the process tab and click “Show processes from all users.”

 

image

 

That’s it, you can now log the other user off.

 

Again, I haven’t got the foggiest idea why this works.  I have that feature checked 99.99% of the time, so I have never run into this problem before.  Obviously more happens behind the scenes than just displaying more processes when you click that button.

 

Anyways, hope that proves useful to someone at some point. 

 

Now back to our regularly scheduled programming.

Totally Off Topic


AppGameKit Studio

See More Tutorials on DevGa.me!

Month List