Jump to content

Replacing a Graphics sprite


juliogomez7
 Share

Recommended Posts

I made a canvas class for a drawing app and set a white rectangle made with Graphics.drawRect() as its sprite, but I need to change its fill color when I click it. It seems that's not possible according to the few info I've found, so I want to draw another rectangle and change the container sprite but that's not working. Am I doing something wrong? How should I replace the sprite?

 

game.createClass('Canvas', {

  init: function() {

    this.drawContainer = new game.Container();

    var board = new game.Graphics();
    board.visible = false;
    board.beginFill(0xFFFFFF);
    board.lineStyle(0);
    board.drawRect(0, game.system.height /3, game.system.width, 2 * game.system.height / 3 );
    board.endFill();

    this.sprite = fill;

    this.sprite = board;
    this.sprite.interactive = true;

    this.sprite.click = this.click.bind(this);

    this.drawContainer.addChild(this.sprite);

    game.scene.stage.addChild(this.notebookContainer);

  },

  click: function(event) {

    var board = new game.Graphics();
    board.visible = false;
    board.beginFill(0xFF0000);
    board.lineStyle(0);
    board.drawRect(0, game.system.height /3, game.system.width, 2 * game.system.height / 3 );
    board.endFill();

    this.sprite = board;

  }

});

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