简体   繁体   中英

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.

Define function over like this or as you like

function over(item) {

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM