Jump to content

Change state after successful request


ketys
 Share

Recommended Posts

Hi,

I am implementing some complex project, I've got an Angular (MEAN.js) for backend and administration, Phaser for game. Now I've got a question about Phaser game state change. Scenario is: Every user has to choose a position for your village on tilemap, so when he is first logged in, Phaser provides him SignUp game state. After he'll click on the map, Village state must be provided to him.

 

Is better solution than my bellow??

//------------- PHASER CODE ----------------------////in create functiongame.input.onDown.add(function() {    if(this.success) { //create users village        var posX = this.marker.x / 32;        var posY = this.marker.y / 32;        var userVillage = {            'village': {                'position': {                    'tilemapPosX': posX,                    'tilemapPosY': posY                }            }        };        scope.createPlayersCastle(userVillage);    }}, this); //in update functionif(scope.success) game.state.start('Village');  //because of assync request, it have to be in update function// ------------- PHASER CODE END ----------------- //
// ------------- ANGULAR CODE --------------------//$scope.createPlayersCastle = function(playersCastle) {    var user = new Users($scope.user);    user.village = playersCastle.village;           user.$update(function(response) {        $scope.success = true;        Authentication.user = response;    }, function(response) {        $scope.error = response.data.message;    });};

Is there another (better) way than testing scope.success in update function? (something like when createPlayersCastle success etc.)

Thanks

 

Link to comment
Share on other sites

I'd stay away from mixing Angular and Phaser together. Angular's not meant for real-time usage and has its own async update loop outside of Phaser's. That, and the $scope.apply() calls you'll need from within Phaser to sync your Angular app will probably end up stopping your game with a noticeable jank.

 

You're probably better off making direct XHR calls yourself to your server to maintain the state instead of going through Angular's scope semantics and some model layer that updates via $resource or $http.

 

Phaser has signals, a way of subscribing to async notifications from within your game. You could subscribe to the model updates in some globally available signal (even using addOnce when you're expecting one reply, success or failure).

Link to comment
Share on other sites

I've got a lot of code done yet (so I'm not going to change used technologies), it's a business application with gamification elements, so I've managed to not make the whole app in Phaser, because it's not a classic game. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...