ZeroRaptor Posted July 30, 2018 Share Posted July 30, 2018 Hi all, I'm quite new to Phaser, so there may be a simple solution to my problem, but I've been stuck on it for a while. I'm trying start a tween from inside a mouseover event, I've tried putting the tween inside the event, as well as using .start() inside the event to start the tween defined elsewhere. Everything I try just freezes all other tweens on the page. I encountered the same problem with the mouseout event. gameScene.create = function(){ var heart = this.add.sprite(400,300,'heart').setInteractive(); this.input.on('pointerover', function (event, gameObjects) { var tween = this.tweens.add({ targets: heart, alpha: { value: 0, duration: 3000, delay:2000}, }); }); }; Thanks Link to comment Share on other sites More sharing options...
samme Posted July 31, 2018 Share Posted July 31, 2018 On 7/30/2018 at 7:54 AM, ZeroRaptor said: Everything I try just freezes all other tweens on the page. Open the browser console. Link to comment Share on other sites More sharing options...
ZeroRaptor Posted August 1, 2018 Author Share Posted August 1, 2018 23 hours ago, samme said: Open the browser console. Not sure what this means Link to comment Share on other sites More sharing options...
samme Posted August 1, 2018 Share Posted August 1, 2018 Quote Cannot read property 'add' of undefined var tween = (undefined).add({ targets: heart, alpha: { value: 0, duration: 3000, delay:2000}, }); FKL34TI5T5 1 Link to comment Share on other sites More sharing options...
prob Posted August 1, 2018 Share Posted August 1, 2018 The issue is not with Phaser, but with the context of your mouseover tween. Give this a read: https://scotch.io/tutorials/understanding-scope-in-javascript. Link to comment Share on other sites More sharing options...
FKL34TI5T5 Posted February 15, 2020 Share Posted February 15, 2020 On 8/1/2018 at 1:54 PM, prob said: The issue is not with Phaser, but with the context of your mouseover tween. Give this a read: https://scotch.io/tutorials/understanding-scope-in-javascript. That's an Eli the Computer Guy after a Comic Book Guy clip binge answer. I think it is more productive for everyone to be more detailed. Obviously you must pass in the scene. You can do `var _this = this` outside of the function and `_this.add` in it. Samme said the same thing in a much more positive think for yourself approach. Why is it undefined? Even understanding the quirkiness of JS scope perfectly is not going to help you here if you brainfart. We are very dumb animals as humans, especially when tired. Link to comment Share on other sites More sharing options...
Recommended Posts