Inheritance Phaser.Sprite.prototype graphics

Recommended Posts


How can I do something like this:, game, x, y , graphics);

Where graphics is:

graphics =, 0);
game.add.sprite(x, y);

This doesn't help me because I have to make something like this:

MonsterBunny = function (game, x, y, rotateSpeed) {, game, x, y, 'bunny');

    this.rotateSpeed = rotateSpeed;


MonsterBunny.prototype = Object.create(Phaser.Sprite.prototype);
MonsterBunny.prototype.constructor = MonsterBunny;

 * Automatically called by World.update
MonsterBunny.prototype.update = function() {

    this.angle += this.rotateSpeed;


To be able to do:

var wabbit = new MonsterBunny(game, 200, 300, 1);

Thank you

Share this post

Link to post
Share on other sites

If I understand you correctly you want to create sprite based on a custom texture that you create in memory (i.e. bitmap data)?

With your graphics object you can use the generateTexture() method to get a texture that you can initialize your sprite with.

graphics =, 0);

sprite = game.add.sprite(400, 300, graphics.generateTexture());

Another way of doing it is to create a BitmapData object instead of using graphics, draw on it, and then use that as your texture for the sprite (this code is from the example at

// create a new bitmap data object
var bmd = game.add.bitmapData(128,128);

// draw to the canvas context like normal
bmd.ctx.fillStyle = '#ff0000';

// use the bitmap data as the texture for the sprite
var sprite = game.add.sprite(200, 200, bmd);


Share this post

Link to post
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.