Jump to content

Alter game from outside of the class


grg121
 Share

Recommended Posts

Hi there! I'm trying to make a browser game inspired in https://codecombat.com/ to teach people to programe in python.

 

I'm using Django as web framework and phaser to make the game visualization but, what I would like to do is not control the game with keyboard or mouse but let the user write python code in django interface  and made that python code (which would be executed by django server) call JS functions to alter the phaser game status.

 

I'm not sure about the viability of this but I would like to try. My problem here is that, if I write a function in my game object or even an atribute in my create() function:

 

this.Impulse = function(){
      this.physics.velocityFromRotation(player.rotation+90, 100, player.body.acceleration);
    }

this.color = "red" ;

 

 

and then, in the broser console I wrote  mygame.color or mygame.Impulse I got: undefined 

 

I'm reading phaser3 docs but I'm not an experienced javascript programmer and I'm not sure what scope do my function/atribute have.

 

Can you help me?? Thank you so much :)

Link to comment
Share on other sites

You can access the scene from the initial game object.

For example:

var game = new Phaser.Game(config);

game.scene.keys.theSceneYouWantToAccess.physics.velocityFromRotation();

You also have a few other options here like creating global variables or trigger events.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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