bexphones Posted August 29, 2017 Share Posted August 29, 2017 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) } } Link to comment Share on other sites More sharing options...
Recommended Posts