Jump to content

Tween inside mouseover event


Recommended Posts

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},


Link to comment
Share on other sites

  • 1 year later...
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...