Jump to content

Dynamic Simple Texture


Recommended Posts

Hello, there is a way to create by code a texture of size W and H ? 

Texture.WHITE creates a 10x10 texture but if you change it size after adding it into a PIXI.Sprite it will resize back to 10x10.

If you resize it after assign it to the Sprite it will change the scale.

I need it basically because the "containsPoint" function only works based on the texture size or the Sprite.

Link to post
Share on other sites

what about this?. seems easier and seems to work fine:

 

   function createTexture(params) {
        params = Object.assign({ width: 10, height: 10, color: 'white' }, params)
        const canvas = document.createElement('canvas');
        canvas.width = params.width;
        canvas.height = params.height;
        const context = canvas.getContext('2d');
        context.fillStyle = params.color;
        context.fillRect(0, 0, params.width, params.height);
        return new PIXI.Texture(new PIXI.BaseTexture(canvas));
   }

 

Link to post
Share on other sites
const myWhiteTexture = new PIXI.Texture(PIXI.Texture.WHITE, new PIXI.Rectangle(0, 0, params.width, params.height), new PIXI.Rectangle(0, 0, params.width, params.height));

anyway, please check if it works. It might have a problem on CanvasRenderer because of https://github.com/pixijs/pixi.js/pull/4800

If it works, we'll have no extra memory. and all all the "white" textures will be batched because they have the same base texture.

As for color, you can assign tint to the sprite.

If this thing works, I'll add it to wiki as simple method that doesnt require extra memory.

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.

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...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...