Jump to content

Frame does not fit inside base Texture dimensions


HelloWorld123
 Share

Recommended Posts

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 :D

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 :D

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