Jump to content

baseTexture from loader alias


Recommended Posts

How does one create a base texture from a "named" image referencing the "alias" used in loader.

PIXI.loader.add("sprites", "sprites.png")
new PIXI.BaseTexture.fromImage("sprites.png", false, PIXI.SCALE_MODES.NEAREST)

It seems to me it would make more sense to stick to "sprites" instead of "sprites.png".

Link to comment
Share on other sites

No need to use fromX methods, just use the resources the loader made for you:

PIXI.loader.add("sprites", "sprites.png");
PIXI.loader.load(function () {
    const baseTexture = PIXI.loader.resources.sprites.texture.baseTexture;

    // loader made you a base texture, no need to create your own.

Additionally, don't do "new PIXI.BaseTexture.fromX()" the from methods are not a constructor. Either do "new PIXI.BaseTexture()" or do "PIXI.BaseTexture.from()" or (my preference) do neither and just use the one the loader made for you.

Link to comment
Share on other sites

My sprites has no baseTexture:


So it's crashing here:

	.add("sprites", "sprites.png")
	.load(function() {
		g.ui.sprites.base = PIXI.loader.resources.sprites.baseTexture;
        // Next line fails as g.ui.sprites.base is undefined
		g.ui.sprites.player = new PIXI.Texture(g.ui.sprites.base, new PIXI.Rectangle(0, 0, 160, 110));


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