juliogomez7

Replacing a Graphics sprite

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;

  }

});

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.