Jump to content

Extracting sprites from screenshots


dreamwebspace
 Share

Recommended Posts

this will depend what engine rendering you use.

here a part of example with canvas pixi and nwjs

This , save all children sprites with alpha

        setTimeout(function(){ // wait rendering to 0,0 update _displayX,_displayY
            SceneManager._scene._active = false;
            var fs = require('fs');
            var pathName = `img/parallaxes/${$dataMap.parallaxName}.png`;
            var snap = Bitmap.snap2(target);
            var urlData = snap._canvas.toDataURL();
            var base64Data = urlData.replace(/^data:image\/png;base64,/, "");
            fs.writeFile(pathName, base64Data, 'base64', function(error){
                if (error !== undefined && error !== null) {  console.error('An error occured while saving the screenshot', error); } 
            });
            // PHOTOSHOP MODE
            if(option["c-save_psd"]){
                var newFolderPath = `img/parallaxes/_psd_${$dataMap.parallaxName}`;
                if(!fs.existsSync(newFolderPath)){ fs.mkdirSync(newFolderPath)}; // create folder if not exsit
                    
                for (let i = 0; i < target._spriteset.displayLayers.length; i++) {
                    let layer = target._spriteset.displayLayers[i];
                    let pathName = `${newFolderPath}/${$dataMap.parallaxName}_psd_layer${i}.png`;
                    let snap = Bitmap.snap2(layer);
                    let urlData = snap._canvas.toDataURL();
                    let base64Data = urlData.replace(/^data:image\/png;base64,/, "");
                    fs.writeFile(pathName, base64Data, 'base64', function(error){
                        if (error !== undefined && error !== null) {  console.error('An error occured while saving the screenshot', error); } 
                    });
                }
            };
            
            iziToast.warning({
                transitionOut: 'fadeOutUp',
                id:'loading',
                timeout:false,
                theme: 'dark',
                icon: 'icon-person',
                title: 'Rendering and Compile Json Complette',
                message: 'please Reload',
                position: 'topCenter', // bottomRight, bottomLeft, topRight, topLeft, topCenter, bottomCenter
                progressBarColor: 'rgb(0, 255, 184)',
                backgroundColor: '#f44242',
                progressBarColor:'#f41002',
            });
     
         }, 300);
    };

    Bitmap.snap2 = function(stage) {
        var width =  $dataMap.width*48;
        var height = $dataMap.height*48;
        var bitmap = new Bitmap(width, height);
        var context = bitmap._context;
        var renderTexture = PIXI.RenderTexture.create(width, height);
        if (stage) {
            Graphics._renderer.render(stage, renderTexture);
            stage.worldTransform.identity();
            var canvas = null;
            if (Graphics.isWebGL()) {
                canvas = Graphics._renderer.extract.canvas(renderTexture);
            } else {
                canvas = renderTexture.baseTexture._canvasRenderTarget.canvas;
            }
            context.drawImage(canvas, 0, 0);
        } else {

        }
        renderTexture.destroy({ destroyBase: true });
        bitmap._setDirty();
        return bitmap;
    };

 

 

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