Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Object constructor using PIXI


___________
 Share

Recommended Posts

Hello! I know this is probably a dumb question but I am quite new to PIXI. I was wondering if you could do something like this with PIXI:

function Object(name, x, y, scale_x, scale_y, image_path)
{
    this = PIXI.loader.add(this.name, image_path).load(function(loader, resources)
    {
	/* 
        The initialization code.
        */
    });
}

I know that wouldn't work but is there anything like that?

Link to comment
Share on other sites

You are doing something very strange, and my question is the next:

why do you need that kind of stuff? Why not just use Sprite.fromFrame or Texture.fromImage? I think you missed something while learning javascript.

function MySprite(name, x, y, scale_x, scale_y, url)
{
  PIXI.Sprite.call(this, new PIXI.Texture(PIXI.Texture.Empty.BaseTexture));
  this.position.set(x, y);
  this.scale.set(scale_x, scale_y);
  PIXI.loader.add(name, url, function(lo, res) => {
    this.texture = res;
  })
}

MySprite.prototype = Object.create(PIXI.Sprite);
MySprite.prototype.constructor = MySprite;

 

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