brainbass Posted November 30, 2017 Share Posted November 30, 2017 Hi, I use phaser 2.6.1. I have created an animation. This work fine but sometimes this not starting. I dont know why. In create() function i add animations for my spritesheet: this.car = game.add.sprite(game.world.centerX,500, 'car'); this.car.animations.add('mover',[0,1,2,3],1000, true); this.car.fixedToCamera = true; When overlap i start the function for animate this game.physics.arcade.overlap(this.car, this.borders, this.canMove, null, this); This is my function },canMove: function(car, objet){ if(crash == 0){ crash = 1; _this.car.animations.play("mover"); console.log("fire") setTimeout(function(){ _this.car.animations.stop(); _this.car.frame = 0; crash = 0; },1000) } } When the car overlap a border, this function is start. The console.log() show but the animation suddenly not start. I can restart a lot of time my page, suddenly the animation not starting but the console.log() is show. Thanks for your help Link to comment Share on other sites More sharing options...
DanielKlava Posted November 30, 2017 Share Posted November 30, 2017 Hello! Can you check the contents of "_this.car" using "console.log(_this.car)", and see if it's a valid object? And, could you also post the code part where you initialize the "_this" variable? There may be some issue where it doesn't correctly point to the "this" object, so your code may not find the "car" object with the animations set up. Link to comment Share on other sites More sharing options...
brainbass Posted November 30, 2017 Author Share Posted November 30, 2017 Thank you for your reply. I have check _this.car and is a valid object. The console.log(_this.car) triggering but the animation sometimes not working. I initialize "_this" inside create() function _this = this; Link to comment Share on other sites More sharing options...
TomC Posted December 1, 2017 Share Posted December 1, 2017 this.car.animations.add('mover',[0,1,2,3],1000, true); Looks like your setting the speed of animation to 1000 frames per second. Could you try setting it to something lower like 10 or 30? Link to comment Share on other sites More sharing options...
brainbass Posted December 4, 2017 Author Share Posted December 4, 2017 Thanks all. I have found my issue. The issue is because i have first initialized my car with : this.car = game.add.sprite(game.world.centerX,500, 'car'); this.car.animations.add('mover',[0,1,2,3],1000, true); this.car.fixedToCamera = true; _this = this After in my function i call directly my car with _this I used _this because inside setTimeout(), this property is no equal of this of document I dont know why but if i initialize first with this and after i call with _this this is not working fine. Also for resolve my issue i have starting with _this directly. _this = this; _this.car = game.add.sprite(game.world.centerX,500, 'car'); _this.car.animations.add('mover',[0,1,2,3],1000, true); _this.car.fixedToCamera = true; Link to comment Share on other sites More sharing options...
Recommended Posts