glhclhy
glhclhy

Reputation: 37

Phaser hovering over event

I am new to phaser and I am trying to create a "hovering over" event. That is, when the mouse hover over an object, it shows something. Here is the code:

var hoverPS, hoverEG, hoverAQI, AQIBar, ecoBar, pubBar;
var Game = {
    create: function () {
        this.add.sprite(0, 0, 'game-bg');
        this.add.button(30, 7, 'home-btn', this.home, this);
        AQIBar = game.add.sprite(136, 19, 'AQI-bar');
        ecoBar = game.add.sprite(348, 19, 'eco-bar');
        pubBar = game.add.sprite(583, 19, 'pub-bar');
        hoverAQI = game.add.sprite(95, 45, 'hover-AQI');
        AQIBar.inputEnabled = true;
        AQIBar.events.onInputOver.add(over, this);
        AQIBar.events.onInputOut.add(out, hoverAQI);

    },
}

Now I am getting an error saying that for this line

AQIBar.events.onInputOver.add(over, this);

I got this:

Uncaught ReferenceError: over is not defined.

Can someone help with this?

Thank you.

Upvotes: 0

Views: 1692

Answers (1)

Rafiqul Islam
Rafiqul Islam

Reputation: 1646

Define function over like this or as you like

function over(item) {

    item.fill = "#ffff44";
    item.text = "clicked " + clicks + " times";

}

Upvotes: 2

Related Questions