copy from : http://www.codeproject.com/Articles/489346/Diggers-cross-platform-2D-game