johhnyblagger Posted October 6, 2016 Share Posted October 6, 2016 var mySpriteSheetImage = PIXI.BaseTexture.fromImage("img/mySpriteSheet.png"); var spriteTexture1 = new PIXI.Texture(mySpriteSheetImage, new PIXI.Rectangle(x:0, y:0, width:32, height:32)); var spriteTexture2 = new PIXI.Texture(mySpriteSheetImage, new PIXI.Rectangle(x:32, y:0, width:32, height:32)); var spriteTexture3 = new PIXI.Texture(mySpriteSheetImage, new PIXI.Rectangle(x:64, y:0, width:32, height:32)); var mySprite = new PIXI.Sprite(spriteTexture1); stage.addChild(mySprite); The code above loads many sprites from a sprite sheet. This code was found here. Is there a better way to get the same functionality? Quote Link to comment Share on other sites More sharing options...
xerver Posted October 6, 2016 Share Posted October 6, 2016 That is pretty much it. You can generalize it into a loop but that is the basic idea. Quote Link to comment Share on other sites More sharing options...
johhnyblagger Posted October 6, 2016 Author Share Posted October 6, 2016 thank you! so at this tutorial, the author does some fancy things loading images into a texture cache. Why does the code I posted in the first post not have to do that? Quote Link to comment Share on other sites More sharing options...
xerver Posted October 6, 2016 Share Posted October 6, 2016 If you have a manifest file that describes the rectangles of your spritesheet the loader can automatically create all those textures for you. The loader does some cool things, like loading the image and creating a texture for you. fromImage is a shortcut that loads the image and creates a texture. The loader is more powerful in that it supports middleware and can do lots of different pre/post processing on loaded resources. Which is why you can pass it a JSON file from TexturePacker, for example, and the loader will auto detect the image, load it, and create a texture for each frame. It does this by running code very much like what you have above, it just does it for you automatically. Quote Link to comment Share on other sites More sharing options...
johhnyblagger Posted October 6, 2016 Author Share Posted October 6, 2016 ah ok, thank you for the information! 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.