scofieldly Posted September 28, 2016 Share Posted September 28, 2016 hi all, I am a newbie to phaser, currently I am doing a shotting game, and I want to make a auto shot feature. the gun should lock a moving sprite first and shot until the sprite die, so I wonder is there any function that can do the 'lock target' function, thanks Link to comment Share on other sites More sharing options...
megmut Posted September 28, 2016 Share Posted September 28, 2016 This is very rough, but you will want something like this. The lock function will fire when you shoot a bullet setting a variable to false. In your move / update function, check against this value to stop moving it the sprite is locked. A timer is created for 2 seconds, which on completion will trigger the unlock function, releasing the character. You could go a step further and change the timer to an event callback for the shooting animation, but that's optional. Hope this helps! shootBullet() { this.lock(); let bullet = new Bullet(x,y,texture); // instantiation of bullet class this.game.time.events.add(Phaser.Timer.SECOND * 2, this.unlock, this); } lock() { this.locked = true; } unlock() { this.locked = false; } move() { if(!this.locked) { ... // move your char here if not locked } } Jem Kazama 1 Link to comment Share on other sites More sharing options...
scofieldly Posted September 29, 2016 Author Share Posted September 29, 2016 12 hours ago, megmut said: This is very rough, but you will want something like this. The lock function will fire when you shoot a bullet setting a variable to false. In your move / update function, check against this value to stop moving it the sprite is locked. A timer is created for 2 seconds, which on completion will trigger the unlock function, releasing the character. You could go a step further and change the timer to an event callback for the shooting animation, but that's optional. Hope this helps! shootBullet() { this.lock(); let bullet = new Bullet(x,y,texture); // instantiation of bullet class this.game.time.events.add(Phaser.Timer.SECOND * 2, this.unlock, this); } lock() { this.locked = true; } unlock() { this.locked = false; } move() { if(!this.locked) { ... // move your char here if not locked } } hi megmut, thanks for your reply, sorry for my misunderstanding explanation, I did not mean when the bullet collide the target will lock the target. I mean the target will keep moving and the gun will adjust the angle to aim the target and keep shotting. do you have any idea about this feature, thanks. Link to comment Share on other sites More sharing options...
Recommended Posts