Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamebuilderstudio/9245850 to your computer and use it in GitHub Desktop.
Save gamebuilderstudio/9245850 to your computer and use it in GitHub Desktop.
This is an example of manually overriding the default GameBuilder Studio startup sequence to us the NewGrounds API connector to show loading progress and an initial ad for your game. When the full api is officially supported by GameBuilder Studio this code will be auto generated for you by the editor.
package
{
import com.gbs.game.BaseGame;
import com.pblabs.engine.PBE;
import com.pblabs.engine.core.LevelEvent;
import flash.events.Event;
import com.newgrounds.API;
import com.newgrounds.APIEvent;
import com.newgrounds.components.APIConnector;
public class NewGroundsGame extends BaseGame
{
public var apiKey : String = "YOUR-API-KEY";
public var apiEncKey : String = "YOUR-ENCRIPTION-KEY";
public var apiConnected : Boolean = false;
public function NewGroundsGame():void
{
super();
API.addEventListener(APIEvent.API_CONNECTED, onAPIConnected);
var apiConnector : APIConnector = new APIConnector();
apiConnector.apiId = apiKey;
apiConnector.encryptionKey = apiEncKey;
//apiConnector.debugMode = "Simulate Logged-in User";
this.addChild(apiConnector);
//This will display the api connector w/ add on top of everything on the stage and
//Center in the middle of the window.
apiConnector.forceAlwaysOnTop();
apiConnector.addEventListener(MouseEvent.MOUSE_UP, onPlayButtonClicked);
}
/*-----------------------------------------------------------------------------------------------------------
* Public Methods
-------------------------------------------------------------------------------------------------------------*/
public function onAPIConnected(event : APIEvent):void
{
apiConnected = true;
trace("Connected!");
}
public function onPlayButtonClicked(event : MouseEvent):void
{
if(apiConnected)
{
startUp();
}
}
/*
* This is not needed because the NewGrounds API is the loading screen
public function init(event : Event):void
{
startUp();
}
*/
override public function startUp():void
{
if(PBE.started) return;
super.startUp();
//Subclass if you need to
}
/*-----------------------------------------------------------------------------------------------------------
* Protected Methods
-------------------------------------------------------------------------------------------------------------*/
override protected function onLevelLoaded(event : LevelEvent):void
{
//Implement if needed
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment