Jump to content

sprite.on("pointerdown", callback) trouble


TemperTony
 Share

Recommended Posts

Hi guys,

I'm having a bit of trouble using the on click sprite function. So what happens is when I call another function through the on click of the sprite, the function isn't able use a  variable that was defined in the constructor 

        this.isOpen = false

        this.icon = new PIXI.Sprite.fromFrame('icons/inventoryclose.png')
        this.icon.interactive = true
        this.icon.buttonMode = true
        this.icon.on("pointerdown", this.toggle)
        this.addChild(this.icon)
    toggle() {
        this.isOpen = true

    }

Rather than being able to set this.isOpen = true, it doesn't know of it.

Am I doing something wrong? Any help would be awesome

Link to comment
Share on other sites

It looks like the display object is contained in an outer object, so event.currentTarget will be this.icon (the sprite), not the desired outer object (this).

Also InteractionManager just passes the eventData, not any context, judging from its dispatchEvent method:

displayObject[eventString](eventData);

 

It would be awseome if could pass context thoug:)

Link to comment
Share on other sites

InteractionManager calls the event handler function that you supply but it doesn't call it on an object. bind makes it like the function is called on the object that was passed to bind.. Er it's hard to explain well but Mozilla's docs on this and bind can explain better I think:)

EDIT: that's a little better but the Mozilla docs are better still:)

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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