fubeca6 Posted September 6, 2014 Share Posted September 6, 2014 Good Evening, I'm trying to create a blinking tile. Here's what I have so far:function create() { this.timer = game.time.create(false); this.timer.loop(1000, updateCounter, this); this.timer.start();}function updateCounter() { if (this.burn) { this.burn.kill(); } else { createBurn(); }}function createBurn() { this.burn = game.add.sprite(224, 352, 'burn'); game.physics.enable(this.burn, Phaser.Physics.ARCADE); this.burn.body.immovable = true;}However, when I run this, it simply creates the tile over and over without ever killing it -____- I've toyed around a lot with the Phaser Timer examples, etc. but haven't been able to get it quite right. Any help would be greatly appreciated! Thanks Link to comment Share on other sites More sharing options...
Dumtard Posted September 6, 2014 Share Posted September 6, 2014 You shouldn't be adding a new sprite every time, you can just call Sprite.revive() to bring a dead sprite back.Also depending on your goal for this sprite a better approach may be to create an animation for the sprite and run that. Link to comment Share on other sites More sharing options...
fubeca6 Posted September 6, 2014 Author Share Posted September 6, 2014 Thanks Dumtard, that did it! My overall code looks like this now (for anyone else with a similar problem):function create() { this.burn = game.add.sprite(224, 352, 'burn'); game.physics.enable(this.burn, Phaser.Physics.ARCADE); this.burn.body.immovable = true; this.timer = game.time.create(false); this.timer.loop(1000, updateCounter, this); this.timer.start();} function updateCounter() { if (this.burn.exists) { this.burn.kill(); } else { this.burn.revive(); }} Link to comment Share on other sites More sharing options...
Recommended Posts