Jump to content

Sprite inheritance - setting graphics object width and height


Recommended Posts

How can I set the bounds of an graphics object that is added as a child to a sprite?

When I check the height, it is always 32.

BigButton = function ( game, x, y, width, cornerRadius, label ) {    var width = width;    var height = 40;    var x = x;    var y = y;    var radius = 6;    var padding = 20;    var self = this;    Phaser.Sprite.call(this, game, 0, 0);    // Create background    var graphics = game.make.graphics(0, 0);    // Add text    var style = { font: "18px din_lightregular", fill: "#ffffff", align: "center"};    var text = new Phaser.Text(game, x, y, label, style);    // Position relative to x/y    text.x = x + width / 2 - text.width / 2;    text.y = y + height / 2 - text.height / 2;    height = text.height + padding;    // draw the rounded rectangle    graphics.beginFill(0x662D91);    graphics.drawRoundedRect(x, y, width, height, cornerRadius);    graphics.endFill();    // Add graphics and text to sprite    this.addChild(graphics);    this.addChild(text);    game.add.existing(this);};BigButton.prototype = Object.create(Phaser.Sprite.prototype);BigButton.prototype.constructor = BigButton;

Thanks in advance.

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