Hydromel

Members
  • Content Count

    13
  • Joined

  • Last visited

About Hydromel

  • Rank
    Member

Profile Information

  • Gender
    Female
  • Location
    France
  1. Hydromel

    Ajax callback in Phaser using states

    Hey MikeW, Ajax is calling every minutes anim function with arguments (from php request on a API). I tried to put anim function definition on top of ScriptState prototype but I've got the same error. Hey megmut, If I understand your answer, I have to create a new customEvent in Ajax.js, listen to this event in my scriptState and then where do I have to place anim fonction definition ? Thanks guys !
  2. Hey everybody, excuse my poor english ! I was using a single JS file for my program structured like this : index.html with <div id="timediv"></div> script.js with my Phaser code including anim function called in ajax.js. This function was declared after the update in script.js. ajax.js with function refreshdiv() which call lance() which call anim() every 60 seconds. Everything was ok like this Now I want to use states. I made : bootState, loadState and the main state called scriptState. But where do I have to place anim() declaration now ? I tried different places (in scriptState, after update, in create, in update, in bootState init etc...) but I have always the same message : Thanks a lot for your help !
  3. Hydromel

    Problem with global function in emitters

    Hey, it's the first time I use Jsfiddle, it's not a success... https://jsfiddle.net/ydshae9q/
  4. Hydromel

    Problem with global function in emitters

    Hello AzraelTycka and thanks for your answer, In my first emitter, this refers to 'Window → http://localhost/' and this.child refers to undefined. I tried to replace declenche by MyGame.StateA.declenche but I have the message Error: Phaser.Signal: listener is a required param of add() and should be a Function. It seems that MyGame.StateA.declenche is not recognised as a function... Then I tried to bind the keyword "this" as you said : particle.events.onInputDown.add({console.log(this.declenche)}.bind(this),this); but it says Phaser.StateManager - No state found with the key: StateA
  5. Hydromel

    Problem with global function in emitters

    No, error message is the same. It's ok when I put the function inside the forEach,for example : this.emitterVert.forEach(function(particle){ particle.inputEnabled = true; particle.events.onInputDown.add(declenche, this) ; function declenche(){ particle.kill(); } }); but I want a global function...
  6. Hydromel

    Problem with global function in emitters

    Thanks for your help Ivasik. I tried : particle.events.onInputDown.add(this.declenche, this); and even : particle.events.onInputDown.add(declenche, this.parent); but the problem is still there... The context is a bit difficult to follow.
  7. Hey, I've got six emitters and a callback function for each inputDown on particle. I would like to declare a global function but maybe the context is not ok : my function seems not to be defined "ReferenceError: declenche is not defined". Thanks a lot for your help ! MyGame.StateA = function (game) { this.background = null; this.sprite = null; this.windMax = 0; this.emitter1 = null; this.emitter2 = null; this.emitter3 = null; this.emitter4 = null; this.emitter5 = null; this.emitter6 = null; }; MyGame.StateA.prototype = { create: function () { this.background = this.add.sprite(0, 0, 'background'); this.background.width = this.game.width; this.background.height = this.game.height; this.sprite = this.add.sprite(this.world.centerX, this.world.centerY, 'graphics'); this.sprite.anchor.set(0.5); music = this.add.audio('music'); music.loop = true; music.play(); this.emitter1 = this.add.emitter(this.world.centerX, this.world.height, 1); this.emitter1.makeParticles('dragee1'); this.emitter1.setYSpeed(-10, -50); this.emitter1.gravity = 0; this.emitter1.width = 800; this.emitter1.setRotation(); this.emitter1.forEach(function(particle){ particle.inputEnabled = true; particle.events.onInputDown.add(declenche, this.child) ; }); this.emitter2 = this.add.emitter(this.world.centerX, this.world.height - 50, 1); this.emitter2.makeParticles('dragee2'); this.emitter2.setYSpeed(-25, -75); this.emitter2.gravity = 0; this.emitter2.width = 800; this.emitter2.setRotation(); this.emitter2.forEach(function(particle){ particle.inputEnabled = true; particle.events.onInputDown.add(declenche, this) ; }); this.emitter3 = this.add.emitter(this.world.centerX, this.world.height - 100, 1); this.emitter3.makeParticles('dragee3'); this.emitter3.setYSpeed(-15, -55); this.emitter3.gravity = 0; this.emitter3.width = 800; this.emitter3.setRotation(); this.emitter3.forEach(function(particle){ particle.inputEnabled = true; particle.events.onInputDown.add(declenche, this) ; }); this.emitter4 = this.add.emitter(this.world.centerX, this.world.height - 150, 1); this.emitter4.makeParticles('dragee4'); this.emitter4.setYSpeed(-20, -60); this.emitter4.gravity = 0; this.emitter4.width = 800; this.emitter4.setRotation(); this.emitter4.forEach(function(particle){ particle.inputEnabled = true; particle.events.onInputDown.add(declenche, this) ; }); this.emitter5 = this.add.emitter(this.world.centerX, this.world.height - 200, 1); this.emitter5.makeParticles('dragee5'); this.emitter5.setYSpeed(-5, -45); this.emitter5.gravity = 0; this.emitter5.width = 800; this.emitter5.setRotation(); this.emitter5.forEach(function(particle){ particle.inputEnabled = true; particle.events.onInputDown.add(declenche, this) ; }); this.emitter6 = this.add.emitter(this.world.centerX, this.world.height - 250, 1); this.emitter6.makeParticles('dragee6'); this.emitter6.setYSpeed(-30, -80); this.emitter6.gravity = 0; this.emitter6.width = 800; this.emitter6.setRotation(); this.emitter6.forEach(function(particle){ particle.inputEnabled = true; particle.events.onInputDown.add(declenche, this) ; }); this.emitter1.start(false, 40000, 300); this.emitter2.start(false, 32000, 300); this.emitter3.start(false, 28000, 300); this.emitter4.start(false, 24000, 300); this.emitter5.start(false, 20000, 300); this.emitter6.start(false, 16000, 300); }, resize: function (width, height) { this.background.width = width; this.background.height = height; this.sprite.x = this.world.centerX; this.sprite.y = this.world.centerY; }, update: function () { }, declenche: function (){ m1= game.add.audio('[M1]'); m2= game.add.audio('[M2]'); m3= game.add.audio('[M3]'); m4= game.add.audio('[M4]'); s1= game.add.audio('[S1]'); s2= game.add.audio('[S2]'); s3= game.add.audio('[S3]'); var sons=[m1,m2,m3,m4,s1,s2,s3]; var randomSon = Phaser.ArrayUtils.getRandomItem(sons); randomSon.play(); var style = { font: "16px Georgia", fill: "#ffffff", align: "center"}; tx = game.add.text(particle.x,particle.y, randomSon.key, style); particle.kill(); } };
  8. Hydromel

    WebAudio panner + Phaser

    Hi GreenishFlow, You have a good example here : https://developer.mozilla.org/fr/docs/Web/API/PannerNode I already used the panner.setPosition but not the listener.setOrientation. Excuse my english, I'm french. function playPas(marcheur) { sourcePas = context.createBufferSource(); //you tell to the source which sound to play //I had a random choice between 3 sounds var choix = Math.round(2*Math.random()); console.log("choix pas "+ choix); switch (choix) { case 0: sourcePas.buffer = pas1Buffer.buf; console.log("play Pas 1"); break; case 1: sourcePas.buffer = pas2Buffer.buf; console.log("play Pas 2"); break; case 2: sourcePas.buffer = pas3Buffer.buf; console.log("play Pas 3"); break; } //You connect the source to the context sourcePas.connect(marcheur.panner); sourcePas.loop=true; //console.log(marcheur.panner); sourcePas.start(0); //console.log("play Pas"); }Then in the update : //ajusting the panner : I had to divide /1000 to have a good sensation of distance var pasx = boy[j].pb.body.x/1000; var pasy = boy[j].pb.body.y/1000; pasx = (pasx - 0.960)*2; //zero is on the center bottom of the screen pasy = (1.088 - pasy)*2; boy[j].panner.setPosition(pasx,pasy,1);I hope it will help !
  9. Hydromel

    How to stop moveTo

    No problem with animation, the tween can be combine with animation, thanks a lot ! But what about obstacles and collisions ? If velocity and gravity can't affect the boy, he can't get around the buildings ? even with : game.physics.startSystem(Phaser.Physics.ARCADE);(...)game.physics.arcade.enable(building1);(...)game.physics.arcade.enable(building2);(...)game.physics.arcade.enable(boy);(...)game.physics.arcade.collide(boy, building1);game.physics.arcade.collide(boy, building2);
  10. Hydromel

    How to stop moveTo

    Ok, but then how to tween the boy walking with sprite animation if body.moves = false ?
  11. Hydromel

    How to stop moveTo

    I tried to use tweens with this example but the boy have shaking movements even if animations are disactivated (idem with velocity). Do you see what is wrong ? var game = new Phaser.Game(1920,1088,Phaser.AUTO,'content',{preload: preload, create:create,update:update});var xmin=160;var ymin=160;var myPoint1 = new Phaser.Point(game.rnd.integerInRange(100, 200),game.rnd.integerInRange(ymin+60, ymin+80));var myPoint2 = new Phaser.Point(game.rnd.integerInRange(-100, 1800),game.rnd.integerInRange(ymin, 800));var boy;var sortieBoy;var s;function preload(){game.load.image('map', 'assets/sky.png');game.load.image('building1', 'assets/building1.png');game.load.image('building12', 'assets/building2.png');game.load.spritesheet('boy','assets/boy_nb.png',22,23);}function create(){game.physics.startSystem(Phaser.Physics.ARCADE);game.add.sprite(0, 0, 'map');building1=game.add.sprite(xmin, ymin, 'building1');game.physics.arcade.enable(building1);building1.anchor.setTo (0.5,0.5);building1.body.immovable = true;building12=game.add.sprite(420, 420, 'building2');game.physics.arcade.enable(building12);building12.anchor.setTo (0.5,0.5);building12.body.immovable = true;boy=game.add.sprite(160,180,'boy');game.physics.arcade.enable(boy);//boy.anchor.setTo (0.5,0.5);boy.animations.add('walk',[3,4,5],10,true);boy.animations.add('up',[0,1,2],10,true);boy.animations.add('down',[6,7,8],10,true);boy.frame=7;//boy.animations.play('descent');boy.body.velocity.x = game.rnd.integerInRange(-100, 100);boy.body.velocity.y = game.rnd.integerInRange(-100, 100);sortieBoy = game.add.tween(boy); sortieBoy.to({x: myPoint1.x, y: myPoint1.y}, 1000, Phaser.Easing.Linear.None);sortieBoy.onComplete.add(firstTween, this);sortieBoy.start();}function firstTween() { s = game.add.tween(boy); s.to({x: myPoint2.x, y: myPoint2.y}, 1000, Phaser.Easing.Linear.None); s.start(); //boy.animations.play('marche');}function update(){game.physics.arcade.collide(boy, bu_sante);game.physics.arcade.collide(boy, bu_sante2);}Thanks for your help
  12. Hydromel

    How to stop moveTo

    Thanks a lot, I will try all this
  13. Hydromel

    How to stop moveTo

    Hello, I'm trying to schedule 2 animations : first the boy goes out of the building, then he crosses the scene . Here's my code : var game = new Phaser.Game(1920,1088,Phaser.AUTO,'content',{preload: preload, create:create,update:update});var xmin=160;var ymin=160;var myPoint1 = new Phaser.Point(game.rnd.integerInRange(100, 200),game.rnd.integerInRange(ymin+60, ymin+80));var myPoint2 = new Phaser.Point(game.rnd.integerInRange(-100, 1800),game.rnd.integerInRange(ymin, 800));function preload(){game.load.image('map', 'assets/sky.png');game.load.image('building1', 'assets/building1.png');game.load.image('building12', 'assets/building2.png');game.load.spritesheet('boy','assets/boy_nb.png',22,23);}function create(){game.physics.startSystem(Phaser.Physics.ARCADE);game.add.sprite(0, 0, 'map');building1=game.add.sprite(xmin, ymin, 'building1');game.physics.arcade.enable(building1);building1.anchor.setTo (0.5,0.5);building1.body.immovable = true;building12=game.add.sprite(420, 420, 'building2');game.physics.arcade.enable(building12);building12.anchor.setTo (0.5,0.5);building12.body.immovable = true;boy=game.add.sprite(160,180,'boy');game.physics.arcade.enable(boy);//boy.anchor.setTo (0.5,0.5);boy.animations.add('walk',[3,4,5],10,true);boy.animations.add('up',[0,1,2],10,true);boy.animations.add('down',[6,7,8],10,true);boy.frame=7;boy.body.velocity.x = game.rnd.integerInRange(-100, 100);boy.body.velocity.y = game.rnd.integerInRange(-100, 100);}function update(){game.physics.arcade.collide(boy, building1);game.physics.arcade.collide(boy, building12);game.physics.arcade.moveToObject(boy,myPoint1,60,0);boy.animations.play('down');if (Phaser.Point.distance(myPoint1, boy) < 1){ //alert('test condition'); game.physics.arcade.moveToObject(boy,myPoint2,60,0); boy.animations.play('walk');}}But the animation does'nt change even the condition is true. Maybe I have to stop the first moveTo ? but how ? Thank you for your help !