HelloWorld123 Posted March 19, 2019 Share Posted March 19, 2019 var imageContainer = new PIXI.Container(); PIXI.loader.add("http://127.0.0.1:54508/resources/data/data.jpg").load(function(loader, resources){ var base = resources['http://127.0.0.1:54508/resources/data/data.jpg'].texture.baseTexture; var maxWidth = 2048; var maxHeight = 2048; for (var x = 0; x < base.width; x += maxWidth){ for (var y = 0; y < base.height; y += maxHeight){ var minWidth = Math.min(maxWidth, base.width - x); var minHeight = Math.min(maxHeight, base.height - y); var canvas = document.createElement('canvas'); canvas.width = minWidth; canvas.height = minHeight; canvas.getContext('2d').drawImage(base.source, -x, -y); var texture = new PIXI.Texture( PIXI.BaseTexture.fromCanvas(canvas), new PIXI.Rectangle(x, y, minWidth, minHeight) ); var sprite = new PIXI.Sprite(texture); imageContainer.addChild(sprite); } } viewport.addChild(imageContainer); }); This is a silly question but i'm banging my head for an hour and can't figure it out I'm trying to split an image into smaller texture chunks but i'm getting frame does not fit inside base texture dimensions and i'm not sure why this is happening The image height is 3106 and after the second iteration of the inner loop the y is 2048 and minWidth = 1058 so it should work there is not third iteration of the inner loop to give out of bounds error ... Thanks for reading . also i'm not familiar with ES6 yet, so don't judge ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
HelloWorld123 Posted March 19, 2019 Author Share Posted March 19, 2019 Nevermind i found out my mistake new PIXI.Rectangle(x,y,minWidth, minHeight) > new PIXI.Rectangle(0,0, minWidth, minHeight ) and should change position of the sprites to sprite.position.x = x and sprite.position.y = y ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 19, 2019 Share Posted March 19, 2019 new PIXI.Rectangle(0, 0, minWidth, minHeight) , there's no x,y offset in your new texture HelloWorld123 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 19, 2019 Share Posted March 19, 2019 Note : its possible to add offset in "trim" or in default anchor for texture. But I dont know if that's good for your case, assigning sprite position is easier 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.