timetocode Posted February 22, 2017 Share Posted February 22, 2017 I'm cutting up some large images into puzzle pieces, and I'd like to create spritesheets out of them directly from JavasScript (as opposed to cutting them up and saving them as images which are then loaded as a spritesheet). So far I've made a puzzle cutter in regular canvas. I did these operations in canvas instead of pixi because they are pretty easy in canvas. I can then draw all of these puzzle pieces to a new canvas, and via PIXI.RenderTexture I can begin to create a spritesheet. Ideally I'd like to gain access to a syntax like new PIXI.Sprite.fromFrame(puzzleId + '-' + puzzlePieceIndex) but I'm not sure how to achieve this. I also generate some other important images, like a stroked outline of the puzzle piece which I will later use in-game to great a highlight effect. I've been inspecting the objects created when importing a spritesheet via texturepacker. All I've figured out so far is that pixi creates a hash of image names matched to frame data... basically the name of an image as the key, and a rectangle, within the global pixi object. Is there some trick to this? Can I just create the strings and frame data and shove it all in there an expect it to work? E.g. 'nebula-2830' : { x: 500, y: 500, width: 48, height: 48 } (or whatever). How do I then actually wire it to the texture that I created via the render texture? The metadata created by texturepacker seems overly complicated for what I need here. Also, perhaps this doesn't change anything, but I might try for some really giant puzzles.. puzzles whose images are 4096 px squared or bigger -- for these I would cut them into multiple textures as only certain hardware would cope with those dimensions as is. Here are some images of the puzzle cutter's output in regular canvas: http://timetocode.tumblr.com/post/156841273346/javascript-jigsaw-puzzle-wip Thanks! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 23, 2017 Share Posted February 23, 2017 1. you put it on multiple canvases, max size 4096x4096 2. baseText = new PIXI.BaseTexture(canvas) 3. tex = new PIXI.Texture(baseTex, new PIXI.Rectangle(x, y, width, height) ) You can also use rotations: http://pixijs.github.io/examples/#/demos/texture-rotate.js timetocode 1 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.