Gerente Posted March 29, 2018 Share Posted March 29, 2018 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. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 29, 2018 Share Posted March 29, 2018 you can make a hack: create a Texture based on "Texture.WHITE.baseTexture", override "_updateUvs" that way it always gets (0,0,1,1), change the frame manually, that's how you get new, shiny, your own, white texture Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 29, 2018 Share Posted March 29, 2018 Oh, actually there is one more variant: texture where frame is old (0,0,10,10) but Orig and Trim w/h are as big as you want. No hacks required. There's a bug with it for CanvasRenderer, but its being fixed. Quote Link to comment Share on other sites More sharing options...
Gerente Posted March 29, 2018 Author Share Posted March 29, 2018 I would not be able to do something like that, I need more experience and knowledge. Thanks anyway. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 29, 2018 Share Posted March 29, 2018 Strange. I think I specified the right way, all fields here are covered in docs. OSUblake 1 Quote Link to comment Share on other sites More sharing options...
Gerente Posted March 29, 2018 Author Share Posted March 29, 2018 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)); } Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 29, 2018 Share Posted March 29, 2018 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.