bexphones

Members
  • Content count

    32
  • Joined

  • Last visited

  1. put a prototype outside a state

    hi, thanks both. it works and it works also without game in the 'create:function()' like Théo suggested _mechant = function (game, posx, posy, image) { this.image = image; this.posx = posx; this.posy = posy; Phaser.Sprite.call(this, game, this.posx, this.posy, this.image); game.add.existing(this); }; _mechant.prototype = Object.create(Phaser.Sprite.prototype); var the_game = { create: function () { this.m = new _mechant(game, 100, 100, 'green_circle'); } };
  2. put a prototype outside a state

    hi, i would put a prototype outside a state. this code works well. var the_game = { create: function(game){ _mechant = function(posx,posy,image){ this.image=image this.posx=posx this.posy=posy Phaser.Sprite.call(this,game,this.posx,this.posy,this.image) game.add.existing(this) } _mechant.prototype=Object.create(Phaser.Sprite.prototype) this.m=new _mechant(100,100,'green_circle') }, }; But when i put the prototype outside the state (to reuse them) i have got this error : ReferenceError: game is not defined _mechant = function(posx,posy,image){ this.image=image this.posx=posx this.posy=posy Phaser.Sprite.call(this,game,this.posx,this.posy,this.image) game.add.existing(this) } _mechant.prototype=Object.create(Phaser.Sprite.prototype) var the_game = { create: function(game){ this.m=new _mechant(100,100,'green_circle') }, }; What must i do to bind the game to the prototype ?
  3. Trying to load stages: Invalid Phaser State object given

    Go to this there is a good template about . You need only to put the state in different files. It's all
  4. Excellent ! This works for me. Thanks for sharing. Just a question : why arrow functions don't work in canvas+ ?
  5. hi, i'm trying to implement this effect : i have a circle who's animating to incite the player to click on the screen. next the player click and release a pink player who go to an enemy ( the pink rectangle). I would like to let the player the ability to click several times to release multiple players and each time the player is inactive the animation of the circle to prompt him to click. The problem is that this animation launches several times at the same time as soon as the players are dead. How to code this to avoid this behavior? thanks for your help, because me i don't see the solution https://jsfiddle.net/espace3d/zdnk9cem/ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:preload, create: create, update : update }); function preload() { game.load.image('circle', 'https://s3.postimg.org/bb4aql1lf/touch.png'); game.load.image('rect','https://s26.postimg.org/ci44mlog9/dalle.png') game.load.image('player','https://s26.postimg.org/ikbrd3cw9/bullet_color.png') } var player=[] var enemy var circle var tw_name var tap_ready = true var flag=true var delay_circle_timer = 1500 var counter = -1 //effect on the circle : tween start_tw = (obj,tw_action,tw_name,f) => { tap_ready = true f=true tw_action(obj,tw_name) } // declaration of tw_action tw_action= (obj,tw_name) =>{ obj.alpha=.5 obj.scale.setTo(1,1) tw_name= game.add.tween(obj.scale).to({x:1.5,y:1.5},700,Phaser.Easing.Linear.None,true,delay_circle_timer,-1) tw_name = game.add.tween(obj).to({alpha:0},700,Phaser.Easing.Linear.None,true,delay_circle_timer,-1) tw_name.onStart.add(()=> {obj.visible=true}) } //stop tween stop_tw = (tw_name,f,obj) => { if(f){ obj.visible=false game.tweens.remove(tw_name) f=false } } //launch player and start counter launch_player = (obj)=> { counter++ obj[counter].body.velocity.y=-100 } hide_player_and_start_tw = (obj) => { obj.body.enable=false obj.visible=false start_tw(circle,tw_action,tw_name,flag) } tap = () => { game.input.onTap.add(onTap); function onTap(pointer, doubleTap) { if (!doubleTap && tap_ready){ tap_ready=false //stop the tween on the circle stop_tw(tw_name,flag,circle) //launch the player launch_player(player) //delay for reset tap_ready game.time.events.add(500,() => {tap_ready = true}) } } } function create() { game.physics.startSystem(Phaser.Physics.ARCADE); circle=game.add.sprite(400,300,'circle') circle.anchor.setTo(.5) circle.inputEnabled = true enemy = game.add.sprite(400,100,'rect') enemy.anchor.setTo(.5) game.physics.arcade.enable(enemy) enemy.body.enable=true enemy.body.immovable=true for (var i = 0; i < 10; i++){ player[i]=game.add.sprite(400,600,'player') player[i].anchor.setTo(.5) game.physics.arcade.enable(player[i]) player[i].body.enable=true } //initiate first tween start_tw(circle,tw_action,tw_name,flag) } function update() { tap(circle) for (var i = 0; i < 10; i++){ game.physics.arcade.collide(player[i],enemy,hide_player_and_start_tw) } }
  6. Swordz.io

    why not particle effect when destroy enemies ?
  7. hi mattstyles, you are alright for ternary operator (condition(count) && f) ? true : false //don't work let cond = condition(count) (cond && f) ? true : false //works for the 2nd case, i have found my error. i start an another post about that. on the second post maybe you could give me some advice on my beginnings of functional programming...
  8. animation effect on a click problem

    finded i use an array to store the tween tw_name[0]=.... or it's not necessary because i coudl use one tw_name with 2 different action (alpha and scale). it could be help someone....
  9. animation effect on a click problem

    it's always interesting to reproduce little example i see that my function is ok ...the mistake is somewhere else in my code.... https://jsfiddle.net/espace3d/muh57trm/ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:preload, create: create, update : update }); function preload() { game.load.image('circle', 'https://s3.postimg.org/bb4aql1lf/touch.png'); } var circle var tw_name var tap_ready = true var flag=true var delay_circle_timer = 1500 //tween on the circle start_tw = (obj,tw_action,tw_name,f) => { tap_ready = true f=true tw_action(obj,tw_name) } // declaration of tw_action tw_action= (obj,tw_name) =>{ obj.alpha=.5 obj.scale.setTo(1,1) tw_name= game.add.tween(obj.scale).to({x:1.5,y:1.5},700,Phaser.Easing.Linear.None,true,delay_circle_timer,-1) tw_name = game.add.tween(obj).to({alpha:0},700,Phaser.Easing.Linear.None,true,delay_circle_timer,-1) tw_name.onStart.add(()=> {obj.visible=true}) } //stop tween stop_tw = (tw_name,f,obj) => { if(f){ obj.visible=false game.tweens.remove(tw_name) f=false } } tap = (th) => { game.input.onTap.add(onTap,th); function onTap(pointer, doubleTap) { if (!doubleTap && tap_ready){ //protect the function onTap to avoid double tap tap_ready=false //stop the tween on the circle stop_tw(tw_name,flag,circle) // initiate another tap_ready randomly game.time.events.add(game.rnd.integerInRange(400,2200),() => {start_tw(circle,tw_action,tw_name,flag)}) } } } function create() { circle=game.add.sprite(400,300,'circle') circle.anchor.setTo(.5) circle.inputEnabled = true //initiate first tween start_tw(circle,tw_action,tw_name,flag) } function update() { tap(circle) }
  10. animation effect on a click problem

    hi, I'm trying to have a animation and when i click this animation stop. https://jsfiddle.net/espace3d/5b8yqrez/ The problem is after x click the tween seems to be launch several times at the same time. However i think this snippet does not allow this....where is my error ? have you a another idea to have this behavior ? Thanks var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:preload, create: create }); function preload() { game.load.image('circle', 'https://s3.postimg.org/bb4aql1lf/touch.png'); } var _tw_name=[] var flag=true var circle var delay_circle_timer = 1500 //tween tw = (obj,tw_action,tw_name,f) => { f=true tw_action(obj,tw_name) } // declaration of tw_action tw_action= (obj,tw_name) =>{ obj.alpha=.5 obj.scale.setTo(.1,.1) tw_name[0]= game.add.tween(obj.scale).to({x:1.5,y:1.5},1000,Phaser.Easing.Linear.None,true,delay_circle_timer,-1) tw_name[0] = game.add.tween(obj).to({alpha:0.1},1000,Phaser.Easing.Linear.None,true,delay_circle_timer,-1) tw_name[0].onStart.add(()=> {obj.visible=true}) } //stop tween stop_tw = (tw_name,f,obj) => { if(f){ obj.visible=false game.tweens.remove(tw_name[0]) f=false } } function create() { circle=game.add.sprite(200,200,'circle') circle.anchor.setTo(.5) //initiate first tween tw(circle,tw_action,_tw_name,flag) //simulate a click //stop animation and then relaunch animation simulate_click=() =>{ game.time.events.loop( game.rnd.integerInRange(400,2200),() => {stop_tw(_tw_name,flag,circle);tw(circle,tw_action,_tw_name,flag)}) } game.time.events.add( 2200,simulate_click) }
  11. nobody ? first case : //first console.log(condition(count)) // > true console.log(f) // > true //function 1 if (condition(count) && f){ return true }else{ return false } //return logically true ok! //function 2 but strange result (condition(count) && f) ? true : false //return false ... WHy ? second case : //function 1 > works stop_tw = (tw_name,f,obj) => { if(f){ obj.alpha=0 for(var i=0;i<tw_name.length;i++){ // works but it's the same like for_each! game.tweens.remove(tw_name[i]) } f=false } } //function 2 > don't works and i don't understand why because it's the same than function 1 function for_each(tableau,action){ for(var i=0;i<tableau.length;i++){ action(tableau[i]); } } stop_tw_for_each = (tw_name,f,obj) => { if(f){ obj.alpha=0 for_each(tw_name,game.tweens.remove) //> don't works !!!! f=false } }
  12. another mistery... function foreach(tableau,action){ for(var i=0;i<tableau.length;i++){ action(tableau[i]); } } stop_tw = (tw_name,f,obj) => { if(f){ obj.alpha=0 //foreach(tw_name,game.tweens.remove) > don't works !!!! for(var i=0;i<tw_name.length;i++){ // works but it's the same like foreach! game.tweens.remove(tw_name[i]) } f=false } }
  13. because in this case this snippet return false and i if i do : console.log(condition(count)) // > true console.log(f) // > true // so true && true must return true ???
  14. ok thanks, i understand with a classical if but with a ternary operator what's the good syntax ? (condition(count) && f) ? true : false
  15. Games developed in Phaser

    +1 Wordtris is cool but the music is enervating...