12. - Game runs inside FP 10 Gatcha Wrapper
- Communication through Events
-> Game Events
- Include SWC found at gatcha.com
- GameEvent
- Translations
- SafeMemory
16. Asynchronous start
Using game events
private function onMouseClickStartButton(e:MouseEvent):void
{
! addEventListener(GameEvent.SINGLEPLAYER_START_GAME_RESULT, gatchaStartGameHandler);
! var gatchaStartGameEvent:GameEvent = new GameEvent(GameEvent.SINGLEPLAYER_START_GAME);
! dispatchEvent(gatchaStartGameEvent);
}
private function gatchaStartGameHandler(event:GameEvent):void
{
! startGame();
}
17.
18. End Game
Tell Gatcha Game has ended
private function raceFinished():void
{
! endGame();
}
private function endGame():void
{
! var gatchaEndGameEvent:GameEvent = new GameEvent(GameEvent.SINGLEPLAYER_END_GAME);
! dispatchEvent(gatchaEndGameEvent);
}
19. Gameplay stats
Popularity
total, uniques, duration
Target game
Age
Gender Viral
Location
32. Store Data
With GameEvents
private function raceFinished(level:Number):void
{
! unlockLevel(level + 1);
! var score:Number = calculateHighscore();
! updateHighscore(score);
}
private function unlockLevel(level:Number):void
{
! storeValue(‘unlockedLevel’, level);
}
private function storeValue(key:String, value:String):void
{
! var data:Object = {
! ! "key": key,
! ! "value": value
! };
!
! var storeEvent:GameEvent = new GameEvent(GameEvent.PUT_PERSISTENT_STORAGE, data);
! dispatchEvent(storeEvent);
}
33. Retrieve Data
With GameEvents
private function getValue(key:String):void
{
! addEventListener(GameEvent.GET_PERSISTENT_STORAGE_RESULT, getValueResultHandler);
! addEventListener(GameEvent.GET_PERSISTENT_STORAGE_FAIL, getValueFailHandler);
!
! var getEvent:GameEvent = new GameEvent(GameEvent.GET_PERSISTENT_STORAGE, key);
! dispatchEvent(getEvent);
}
private function getValueResultHandler(event:GameEvent):void
{
! var value:String = event.data;
! //Do something with value
}
private function getValueFailHandler(event:GameEvent):void
{
! //Woops, something went wrong
}
34. Delete Data
With GameEvents
private function deleteValue(key:String):void
{
! addEventListener(GameEvent.DELETE_PERSISTENT_STORAGE_RESULT, deleteValueResultHandler);
! addEventListener(GameEvent.DELETE_PERSISTENT_STORAGE_FAIL, deleteValueFailHandler);
!
! var getEvent:GameEvent = new GameEvent(GameEvent.DELETE_PERSISTENT_STORAGE, key);
! dispatchEvent(getEvent);
}
private function deleteValueResultHandler(event:GameEvent):void
{
! //Deletion succeeded
}
private function deleteValueFailHandler(event:GameEvent):void
{
! //Woops, something went wrong
}
49. Netlog Credits
private function buyNewCar():void()
{
! var data:Object = {
! ! amount: 50,
! ! reason: “Would you like to pay 50 credits for the superkart?”
! };
!
! this.stage.addEventListener(GameEvent.GET_CREDITS_RESULT, creditsResultHandler);
! this.stage.addEventListener(GameEvent.GET_CREDITS_FAIL, creditsFailHandler);
! var getCreditsEvent:GameEvent = new GameEvent(GameEvent.GET_CREDITS, data);
! dispatchEvent(getCreditsEvent);
}
private function creditsResultHandler(event:GameEvent):void()
{
! //User had payed, give him the car
! //Store it in Persistent Storage API :-)
}
private function creditsResultHandler(event:GameEvent):void()
{
! //User has canceled payment
}
50.
51. More information
GATCHA!
http://www.gatcha.com/developers
http://wiki.gatcha.com