Ezelia Posted September 4, 2013 Share Posted September 4, 2013 Hello, Since I use a lot of uniform sprite sheets (same image sizes without a texture packer description file).I noticed that Pixi don't provide a standard way to load such sprite sheet (or maybe I didn't found it ?).so here is a piece of code that do the job.I tried to remain as compatible as possible with PIXI, by adding the frames to TextureCache.code function loadFramedSpriteSheet(textureUrl, textureName, frameWidth, frameHeight, cb){ var image = new PIXI.ImageLoader(textureUrl); var texture = image.texture.baseTexture; var frames=[]; image.addEventListener("loaded", function (event) { var cols = Math.floor(texture.width / frameWidth); var rows = Math.floor(texture.height / frameHeight); var i=0; for (var y=0; y<rows; y++) { for (var x=0; x<cols; x++,i++) { PIXI.TextureCache[textureName+'-'+i] = new PIXI.Texture(texture, { x: x*frameWidth, y: y*frameHeight, width: frameWidth, height: frameHeight }); frames.push(PIXI.TextureCache[textureName+'-'+i]); } } if (typeof cb == 'function') { cb(frames); } }); image.load(); return frames;}Usagevar stage = new PIXI.Stage(0xFFEEFF);var renderer = PIXI.autoDetectRenderer(400, 400);document.body.appendChild(renderer.view);loadFramedSpriteSheet('tileset.png', 'terrain', 64, 64, function(frames) { var terrain = new PIXI.Sprite(frames[8]); //we can also create the sprite from textureCache : //var terrain = PIXI.Sprite.fromFrame('terrain-8'); terrain.position.x = 0; terrain.position.y = 0; stage.addChild(terrain); renderer.render(stage);}); Quote Link to comment Share on other sites More sharing options...
xerver Posted September 4, 2013 Share Posted September 4, 2013 PR? Quote Link to comment Share on other sites More sharing options...
Ezelia Posted September 4, 2013 Author Share Posted September 4, 2013 (what's "PR" ? ) Quote Link to comment Share on other sites More sharing options...
mgutz Posted September 5, 2013 Share Posted September 5, 2013 (what's "PR" ? )Pull Request Quote Link to comment Share on other sites More sharing options...
xerver Posted September 5, 2013 Share Posted September 5, 2013 I'm asking if you would contribute back the changes you made to the original repository. The common way to do that is via a Pull Request (if the code is on GitHub), which is often shorten to PR. Sorry, I forget that not everyone uses GitHub all the time! Quote Link to comment Share on other sites More sharing options...
Ezelia Posted September 5, 2013 Author Share Posted September 5, 2013 oh sure !do you want me to keep the same method name arguments ...etc ? or change something ? Quote Link to comment Share on other sites More sharing options...
Ezelia Posted September 5, 2013 Author Share Posted September 5, 2013 I rewrote the method in a cleaner approach (added it to ImageLoader) here is the PR ==> https://github.com/GoodBoyDigital/pixi.js/pull/311 Quote Link to comment Share on other sites More sharing options...
tharo Posted September 16, 2013 Share Posted September 16, 2013 Hmm. What if I would like to split up the binary texture into multiple textures in order to use it together with the TilingSprite feature?Atm you still use one binary copy of the data with different texture containers pointing to theyr parts. But in fact I would like rlly split it up into different textures. Otherwise TilingSprite wont work in its current state. Any sugestions? Quote Link to comment Share on other sites More sharing options...
xerver Posted September 16, 2013 Share Posted September 16, 2013 @tharo, you can draw only the part you want to a canvas and use that canvas as your texture to tile. Quote Link to comment Share on other sites More sharing options...
tharo Posted September 16, 2013 Share Posted September 16, 2013 Yeah sure .. but somehow I rlly doupt this would be an efficient solution used in hight numbers. Then I would reather load multiple files from the beginning :/ Quote Link to comment Share on other sites More sharing options...
xerver Posted September 17, 2013 Share Posted September 17, 2013 Yeah sure .. but somehow I rlly doupt this would be an efficient solution used in hight numbers. Then I would reather load multiple files from the beginning :/ I wouldn't assume it is bad performance before even trying it. Either way it is going to draw all those images to a canvas, I don't see much difference. Quote Link to comment Share on other sites More sharing options...
tharo Posted September 17, 2013 Share Posted September 17, 2013 Good point. But since the main goal was to reduce javascript object and DOM complexity im not quite sure about it.Another Option could be to use a pixel shader, instead of the on board "tiled" flag, and pass a rect of the source to it. 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.