grg121 Posted December 4, 2018 Share Posted December 4, 2018 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 More sharing options...
rgk Posted December 4, 2018 Share Posted December 4, 2018 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. grg121 1 Link to comment Share on other sites More sharing options...
grg121 Posted December 4, 2018 Author Share Posted December 4, 2018 that what I was looking for, I didn't notice that the physics I wanted to modify was from the scene nor from the game variable... Thank you so much rgk! Link to comment Share on other sites More sharing options...
Recommended Posts