Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon
15. April 2018

A couple days back AppGameKit v2018.4.12 was released with the major new feature being AR (Augmented Reality) support.  I decided to give the new AR functionality a shot and it was really impressive how easy it was.  In order to get started with AR and AppGameKit you are going to need an AR compatible device.  On iOS, this means an ARKit compatible device, which basically means an iPhone 6S or newer device, while on Android device you need an ARCore compatible device from this list of phones.

I modified the AR example slightly, to remove a bit of functionality and to instead load a simple Tie Fighter model I downloaded off the web and converted to .X format.  AppGameKit can be coded using either C++ or their higher level Basic like script, which is what was used in this example.  Here is the slightly modified source code used:

// set window properties
SetWindowTitle( "AR Tie Fighter" )
SetWindowSize( 1024, 768, 0 )

// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetClearColor( 101,120,154 )
SetGenerateMipmaps( 1 )

// camera range from 0.1 meters to 40 meters
SetCameraRange( 1, 0.1, 40 )
SetAmbientColor( 128,128,128 )
SetSunColor( 255,255,255 )

// load tie fighter
LoadObject( 1, "tie.x")
SetObjectPosition( 1, 0,0.1,0 )
LoadImage(1, "diffuse.jpg")
SetObjectImage (1,1,0) 

function ShowModel( show as integer )
  SetObjectVisible( 1, show )

ShowModel( 0 )

function ScaleModel( amount as float )
  SetObjectScalePermanent( 1, amount, amount, amount )

ScaleModel( 0.025 )

// create some planes to show detected surfaces, initially hidden
for i = 101 to 150
  CreateObjectPlane( i, 1,1 )
  SetObjectRotation( i, 90,0,0 )
  FixObjectPivot( i )
  SetObjectVisible( i, 0 )
  SetObjectColor( i, 255,255,255,128 ) // 50% transparent
  SetObjectTransparency( i, 1 )
next i

// add some buttons to control various features
AddVirtualButton( 1, 100,565,100 )
AddVirtualButton( 2, 100,665,100 )
SetVirtualButtonText( 1, "Scale +" )
SetVirtualButtonText( 2, "Scale -" )

AddVirtualButton( 3, 924,665,100 )
SetVirtualButtonText( 3, "Hide" )

function ShowHUD( show as integer )
  SetVirtualButtonVisible( 1, show )
  SetVirtualButtonVisible( 2, show )
  SetVirtualButtonVisible( 3, show )
  SetVirtualButtonActive( 1, show )
  SetVirtualButtonActive( 2, show )
  SetVirtualButtonActive( 3, show )

// initialize AR, if possible
while( ARGetStatus() = 1 )
  // wait while user is being prompted to install ARCore

AnchorID as integer = 0
ShowPlanes as integer = 1
ambientScale# = 1.0

  // get light estimation
  ambient = ARGetLightEstimate() * 255 * ambientScale#
  SetAmbientColor( ambient,ambient,ambient )
  // check screen tap for plane hits, but only if buttons are visible
  if ( GetPointerReleased() and ShowPlanes = 1 )
    // check the point that the user tapped on the screen
    numHits = ARHitTest( GetPointerX(), GetPointerY() )
    if ( numHits > 0 )
      ShowModel( 1 )
      // delete any previous anchor, could keep it around instead
      if ( AnchorID > 0 ) then ARDeleteAnchor( AnchorID )
      // hit test results are ordered from closest to furthest
      // place the object at result 1, the closest
      AnchorID = ARCreateAnchorFromHitTest( 1 )
      ARFixObjectToAnchor( 1, AnchorID )
      // if the user didn't tap on any planes then hide the object
      ShowModel( 0 )
    // clean up some internal resources
  // place the buttons at the edge of the screen
  // needs to be done regularly in case orientation changes
  SetVirtualButtonPosition( 1, GetScreenBoundsLeft()+105, GetScreenBoundsBottom()-210 )
  SetVirtualButtonPosition( 2, GetScreenBoundsLeft()+105, GetScreenBoundsBottom()-105 )
  SetVirtualButtonPosition( 3, GetScreenBoundsRight()-105, GetScreenBoundsBottom()-105 )
  // detect button presses if they are visible
  if ( ShowPlanes = 1 )
    if ( GetVirtualButtonPressed(1) )
      ScaleModel( 1.05 )
    if ( GetVirtualButtonPressed(2) )
      ScaleModel( 0.95 )
    if ( GetVirtualButtonPressed(3) )
      ShowPlanes = 1 - ShowPlanes
      ShowHUD( 0 )
    // screen tap whilst button are hidden shows them again
    if ( GetPointerReleased() )
      ShowPlanes = 1 - ShowPlanes
      ShowHUD( 1 )
  // hide old planes
    for i = 101 to 150
    SetObjectVisible( i, 0 )
  next i
  // show detected planes
  if ( ShowPlanes )
    numPlanes = ARGetPlanes(0)
    // this demo stops at 50 planes, but there is no internal limit
    if numPlanes > 50 then numPlanes = 50
    for i = 1 to numPlanes
      SetObjectPosition( i+100, ARGetPlaneX(i), ARGetPlaneY(i), ARGetPlaneZ(i) )
      SetObjectRotation( i+100, ARGetPlaneAngleX(i), ARGetPlaneAngleY(i), ARGetPlaneAngleZ(i) )
      SetObjectScale( i+100, ARGetPlaneSizeX(i), 1, ARGetPlaneSizeZ(i) )
      SetObjectVisible( i+100, 1 )
    next i
    if ( ShowPlanes )
    Print( "FPS: " + str(ScreenFPS()) )
    select( ARGetStatus() )
      case 2 :  Print( "AR Active" ) : endcase
      case -1 :  Print( "AR Not Available" ) : endcase
      case -2 :  Print( "AR Install Rejected" ) : endcase
    Print( "Number of Planes Detected: " + str(numPlanes) )
    Print( "Light Estimation: " + str(ARGetLightEstimate()) )
    Print( "Light Boost: " + str(ambientScale#,1) )
  // draw the camera feed, and then the rest of the scene

You can see the results of this code and get a bit more detail by watching the video below:

If you are interested in learning more about AppGameKit, be sure to check out our Closer Look available here.


12. April 2018


Phaser 3.4.0 was just released today.   The popular HTML5 game framework has been improving rapidly since the 3.x branch was released earlier this year.   This release includes beta support for the new Game Object Container class, an updated animation API, and much more.  Additionally there were a ton of bug fixes and improvements.  If you are interested in learning more about Phaser 3, be sure to check out our getting started video, which is also embedded below.

New features in this release:

  • A new property was added to Matter.World, correction which is used in the Engine.update call and allows you to adjust the time being passed to the simulation. The default value is 1 to remain consistent with previous releases.
  • Matter Physics now has a new config property getDelta which allows you to specify your own function to calculate the delta value given to the Matter Engine when it updates.
  • Matter Physics has two new methods: set60Hz and set30Hz which will set an Engine update rate of 60Hz and 30Hz respectively. 60Hz being the default.
  • Matter Physics has a new config and run-time property autoUpdate, which defaults to true. When enabled the Matter Engine will update in sync with the game step (set by Request Animation Frame). The delta value given to Matter is now controlled by the getDelta function.
  • Matter Physics has a new method step which manually advances the physics simulation by one iteration, using whatever delta and correction values you pass in to it. When used in combination with autoUpdate=false you can now explicitly control the update frequency of the physics simulation and unbind it from the game step.
  • Matter Physics has two new debug properties: debugShowJoint and debugJointColor. If defined they will display joints in Matter bodies during the postUpdate debug phase (only if debug is enabled) (thanks @OmarShehata)
  • Group.destroy has a new optional argument destroyChildren which will automatically call destroy on all children of a Group if set to true (the default is false, hence it doesn't change the public API). Fix #3246 (thanks @DouglasLapsley)
  • WebAudioSound.setMute is a chainable way to mute a single Sound instance.
  • WebAudioSound.setVolume is a chainable way to set the volume of a single Sound instance.
  • WebAudioSound.setSeek is a chainable way to set seek to a point of a single Sound instance.
  • WebAudioSound.setLoop is a chainable way to set the loop state of a single Sound instance.
  • HTML5AudioSound.setMute is a chainable way to mute a single Sound instance.
  • HTML5AudioSound.setVolume is a chainable way to set the volume of a single Sound instance.
  • HTML5AudioSound.setSeek is a chainable way to set seek to a point of a single Sound instance.
  • HTML5AudioSound.setLoop is a chainable way to set the loop state of a single Sound instance.
  • BitmapText has a new property letterSpacing which accepts a positive or negative number to add / reduce spacing between characters (thanks @wtravO)
  • You can now pass a Sprite Sheet or Canvas as the Texture key to Tilemap.addTileset and it will work in WebGL, where-as before it would display a corrupted tilemap. Fix #3407 (thanks @Zykino)
  • Graphics.slice allows you to easily draw a Pacman, or slice of pie shape to a Graphics object.
  • List.addCallback is a new optional callback that is invoked every time a new child is added to the List. You can use this to have a callback fire when children are added to the Display List.
  • List.removeCallback is a new optional callback that is invoked every time a new child is removed from the List. You can use this to have a callback fire when children are removed from the Display List.
  • ScenePlugin.restart allows you to restart the current Scene. It's the same result as calling ScenePlugin.start without any arguments, but is more clear.
  • Utils.Array.Add allows you to add one or more items safely to an array, with optional limits and callbacks.
  • Utils.Array.AddAt allows you to add one or more items safely to an array at a specified position, with optional limits and callbacks.
  • Utils.Array.BringToTop allows you to bring an array element to the top of the array.
  • Utils.Array.CountAllMatching will scan an array and count all elements with properties matching the given value.
  • Utils.Array.Each will pass each element of an array to a given callback, with optional arguments.
  • Utils.Array.EachInRange will pass each element of an array in a given range to a callback, with optional arguments.
  • Utils.Array.GetAll will return all elements from an array, with optional property and value comparisons.
  • Utils.Array.GetFirst will return the first element in an array, with optional property and value comparisons.
  • Utils.Array.GetRandomElement has been renamed to GetRandom and will return a random element from an array.
  • Utils.Array.MoveDown will move the given array element down one position in the array.
  • Utils.Array.MoveTo will move the given array element to the given position in the array.
  • Utils.Array.MoveUp will move the given array element up one position in the array.
  • Utils.Array.Remove will remove the given element or array of elements from the array, with an optional callback.
  • Utils.Array.RemoveAt will remove the element from the given position in the array, with an optional callback.
  • Utils.Array.RemoveBetween will remove the elements between the given range in the array, with an optional callback.
  • Utils.Array.Replace will replace an existing element in an array with a new one.
  • Utils.Array.SendToBack allows you to send an array element to the bottom of the array.
  • Utils.Array.SetAll will set a property on all elements of an array to the given value, with optional range limits.
  • Utils.Array.Swap will swap the position of two elements in an array.
  • TransformMatrix.destroy is a new method that will clear out the array and object used by a Matrix internally.
  • BaseSound, and by extension WebAudioSound and HTMLAudioSound, will now emit a destroy event when they are destroyed (thanks @rexrainbow)
  • A new property was added to the Scene config: mapAdd which is used to extend the default injection map of a scene instead of overwriting it (thanks @sebashwa)
  • GetBounds getTopLeft, getTopRight, getBottomLeft and getBottomRight all have a new optional argument includeParent which will factor in all ancestor transforms to the returned point.

Getting Started with Phaser 3

GameDev News

12. April 2018


AppGameKit v2018.4.12 was just released on Steam.  The update adds a load of new functionality to the game engine the star of which is AR support for both ARCore and ARKit devices.  Mobile devices also received cloud storage support, iCloud on Apple devices, Google Drive on Android devices.  The release was also packed with minor features and fixes.  If you’ve never heard of AppGameKit, be sure to check out our (somewhat dated) Closer Look review.


Details of the release from the Steam news page:

  • Here's the full Augmented Reality Command List and Values:
    • void ARSetup()AGK
    • int ARGetStatus()
    • void ARUpdateInternal()
    • void ARPause()
    • void ARResume()
    • void ARDestroy()
    • void ARControlCamera()
    • void ARDrawBackground()
    • void ARSetPlaneDetectionMode( int mode )
    • void ARSetLightEstimationMode( int mode )
    • float ARGetLightEstimate()
    • int ARHitTest( float screenX, float screenY )
    • float ARGetHitTestX( int index )
    • float ARGetHitTestY( int index )
    • float ARGetHitTestZ( int index )
    • float ARGetHitTestNormalX( int index )
    • float ARGetHitTestNormalY( int index )
    • float ARGetHitTestNormalZ( int index )
    • int ARGetHitTestType( int index )
    • void ARHitTestFinish()
    • int ARGetPlanes( int reserved )
    • float ARGetPlaneX( int index )
    • float ARGetPlaneY( int index )
    • float ARGetPlaneZ( int index )
    • float ARGetPlaneAngleX( int index )
    • float ARGetPlaneAngleY( int index )
    • float ARGetPlaneAngleZ( int index )
    • float ARGetPlaneSizeX( int index )
    • float ARGetPlaneSizeZ( int index )
    • void ARGetPlanesFinish()
    • int ARCreateAnchorFromHitTest( int index )
    • int ARCreateAnchorFromPlane( int index )
    • void ARFixObjectToAnchor( int objID, int anchorID )
    • int ARGetAnchorStatus( int anchorID )
    • void ARDeleteAnchor( int anchorID )
Find out more about ARCore and which devices are compatible for Android HERE
Learn more about ARKit from Apple HERE.


  • Changed iOS to use an OpenGL ES 3.0 context to support the larger shaders that AppGameKit generates when using multiple features like normal mapping with cascade shadow mapping


  • Minimum supported version of Android is now 4.0.3 (API 15)
  • Updated Google Play Services to version 11.8.0 on Android
  • Added commands to check and request permissions for certain Android features, such as camera access, sdcard read/write access, and GPS location tracking
  • You must start using the new permission commands in your apps, even though they currently auto granted at startup, as a future version of AGK will switch to auto deny, as required by Google
  • Fixed FacebookActivateAppTracking causing a crash on Android
  • Fixed Android orientation changes sometimes causing the AGK render area to be offset from the visible display area
  • Fixed physical keyboards on Android causing edit boxes to not accept any characters if the backspace key was pressed too many times
  • Added 64-bit version of Android for better performance on 64-bit devices
  • Fixed GameCenter commands causing a crash on some Android devices

Cloud Data

  • Added Cloud Data commands to save and load variables to iCloud Drive on iOS and Google Drive on Android which will sync across all devices on the same platform with the app installed
    • SetupCloudData( string reserved )
    • integer GetCloudDataAllowed()
    • integer GetCloudDataChanged()
    • string GetCloudDataVariable( string varName, string defaultValue )
    • SetCloudDataVariable( string varName, string varValue )
    • DeleteCloudDataVariable( string varName )


  • Fixed LoadObject causing a crash with some FBX models, there may be further incompatibilities with newer FBX format specs
  • Added SetShadowCascadeValues command to set the size of each cascade level manually
  • Added DeleteObjectTree command to delete an object plus all attached objects
  • Fixed CreateMemblockFromObjectMesh incorrectly increasing string padding when called on an object created with CreateObjectFromMeshMemblock
  • Fixed SetSpriteAnimation causing a crash if called with a greater number of frames than the previous call
  • Fixed SetObjectMeshFromMemblock crashing if the memblock contains more than 65536 vertices

Video & Camera Fixes

  • Added double buffering to PlayVideoToImage on iOS to avoid flickering on some devices
  • Added double buffering to SetDeviceCameraToImage on iOS to avoid flickering on some devices


  • Fixed GetTweenPlaying commands crashing if a tween chain exists without being played

Text & Fonts

  • Added GetTextAlignment to return the current alignment mode of the text
  • Added DrawText command to draw text immediately to the screen
  • Fixed LoadFont failing to load from the system fonts folder when SetErrorMode is set to 2


  • Fixed JSON conversions being inaccurate with integers over 16 million due to floating point assumptions
  • AppGameKit Type variables that begin with an underscore "_" will now match with JSON fields that don't have the underscore, for example an AppGameKit variable named "_type" will match a JSON field named "type", this allows JSON files to have keywords that can't be used as variable names in AppGameKit


  • Updated Android Tier 2 libraries and projects to use libc++_static instead of stlport_static

System Commands

  • Added GetDeviceNetworkType command to check the current network type (mobile or Wifi) or iOS and Android
  • Added GetStorageRemaining commands to get the current free space and total storage space on iOS and Android
  • Fixed written files sometimes being invisible to external PCs connected via USB
  • Fixed Android videos being replaced with a black texture after resuming the app on some devices


  • Updated Firebase to version 4.5.0 on Android
  • Updated Firebase to version 4.11.0 on iOS
  • Disabled Firebase functionality on Amazon apps due to a crash when it checks for Google Play Services
For all existing users the AppGameKit V2018.04.12 update is now live on Steam.

GameDev News

11. April 2018


A couple years back Unity released a video ADAM that showcased the rendering capabilities of the Unity game engine.  Since then a company called Oat Studios released a sequel and today they released the assets used to create that sequel on the Asset Store.  Additionally they released a EXE version of the trailer, that allows you to jump in as the video is rendered in real-time and relocate the camera.  The asset packs include 3 of the characters used in the trailer as well as the environment they were rendered in.  Be aware that the assets are released under different licenses, so be sure to check each license before you use any of this in your own project.  You can read more about the released here on the Unity blog.

To learn more about the assets, see them in action, as well as seeing the real time movie in action, be sure to watch this video, also embedded below.

GameDev News

9. April 2018


Version 1.2.125 of the Defold Game Engine was just released.  This release is primarily a bug fix release.  If you’ve never heard of it, Defold is an excellent 2D game engine from King that is free for developers to use.  You can learn more about working with Defold in our tutorial series available here.  In addition to the release, there was also a new incredibly handy plugin released by the community named Moku, described below.

Details of the release:


  • DEF-3185 - Added: Added projection helper functions to the default render script
  • DEF-3061 - Fixed: HTML5 rendering issue for Safari.
  • DEF-3209 - Fixed: Multitouch crash on iOS when using more than supported number of touches.
  • DEF-3206 - Fixed: Stopping all playing particlefx on a single particlefx GUI node.
  • DEF-3233 - Fixed: iOS11: App now requests priority over system gestures (i.e. touches at edges)
  • DEF-3217 - Fixed: The SIGABRT signal will now generate a _crash log.
  • DEF-3215 - Fixed: dmLog* functions on iOS now use NSLog.
  • DEF-3162 - Fixed: Changed what part of the script filepath is reported on Lua errors.
  • DEF-3184 - Fixed: Improved link errors for native extensions on Win32.
  • DEF-3197 - Fixed: Resource hashes does not include the factory base path.

Additionally there was a powerful new extension released for the Defold engine.  Moku is a new Defold extension that brings auto-tiling and pathfinding to the Defold engine.

  • Bitmask auto-tiling partially based on the method outlined here: How to Use Tile Bitmasking to Auto-Tile Your Level Layouts. Supports both simple (4-bit) and complex (8-bit) auto-tiling. Can be used in conjuction with defold tilemaps, or your own custom, game-object based maps.
  • AStar pathfinding with support for options such as heavy diagonals, different heuristics, etc
  • Assorted convenience functions including cell picking


A great deal more information, as well as a download link, is available here.

GameDev News

GFS On YouTube

See More Tutorials on!

Month List