Jump to content

Pixijs v3 : Extending Sprite, how to?


Recommended Posts

Hi, i just downloaded v3 and now my button class is not working as it was in v2 (i don't have any message in the console about migration since i made the asked changes )

What is not working is the buttonmode and the mouseevent (they never fire)

Is there a tutorial showing how to do it?



Here is my button script that was working in v2 (more of a test if anything else) : 

JUI.ImageButton = function(a_mainTex, a_hoverTex, a_pressTex, a_disabledTex) {    PIXI.Sprite.call(this);    this._states = [];    this._currentState = 0;    this._mainTex = a_mainTex;    this._hoverTex = a_hoverTex || null;    this._pressTex = a_pressTex || null;    this._disabledTex = a_disabledTex || null;    this.init();};JUI.ImageButton.prototype = Object.create(PIXI.Sprite.prototype);JUI.ImageButton.prototype.constructor = JUI.ImageButton;JUI.ImageButton.prototype.init = function() {    this._stateSprite = new PIXI.Sprite(this._mainTex);    this._states.push(this._mainTex);    if (this._hoverTex)        this._states.push(this._hoverTex);    if (this._pressTex)        this._states.push(this._pressTex);    if (this._disabledTex)        this._states.push(this._disabledTex);    /**     * MouseEvents     */    this.on("mouseover", this._onOver);    /* this.mouseout = this._onOut;     this.mouseup = this._onUp;     this.mousedown = this._onDown;     this.mouseupoutside = this._onUpOutside;     */    //basic props    this.setActive(true);    this.buttonMode = true;    //default state    this._changeState(0);    this.addChild(this._stateSprite);};JUI.ImageButton.prototype._onOver = function(e){    console.log("over");    this._changeState(1);}JUI.ImageButton.prototype._onOut = function(e){    this._changeState(0);}JUI.ImageButton.prototype._onDown = function(e){    this._changeState(2);}JUI.ImageButton.prototype._onUp = function(e){    this._changeState(1);    if (this.onClick) {        this.onClick(e);    }}JUI.ImageButton.prototype._onUpOutside = function(e){    this._changeState(0);}JUI.ImageButton.prototype._changeState = function(a_stateIndex){    this._currentState = a_stateIndex;    this._stateSprite.texture = this._states[this._currentState];}JUI.ImageButton.prototype.setActive = function(a_active){    this.interactive = a_active;    if (a_active)    {        this._changeState(0);    }    else    {        this._changeState(3);    }}JUI.ImageButton.prototype.onClick = null;

Thnaks a lot!

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