Informal discussion about supporting loading images from sprite sheets in R.U.B.E. Upload date: 31 Dec 2012 ============================ Dec 23 (8 days ago) I would like to know if it's possible to use spritesheets with R.U.B.E. Being able to use only a portion of a texture would make it, as the idea behind spritesheets is basically to reuse the same texture for different sprites. That leads us to the concept of having sprites in the scene, rather than images. Having defined the sprites once (in a spritesheet json file or other) would make it easy to reuse them over the scene. As a fellow C++ programmer with some experience in game programming (Cocos2d-x mostly) I offer myself to help and contribute with the development of RUBE. I don't know if this feedback will have my email attached, so I give you my adress: xxx@xxx.com Cheers, Chris Campbell Dec 23 (7 days ago) Hi XXX Thanks for the feedback. The current version of R.U.B.E has no way to select a sub-image from a larger sprite sheet, but I am planning to do that sometime. In fact, one reason I decided to output a glTexCoordPointer array in the JSON as a variable length array is so that more customized image settings can be used in future without changing the JSON format. I have added this to the 'feature voting' page, so we will see how it goes. I will have to do some better research before the time comes to do this, but for now maybe you could tell me: - which package you use to get the sprite sheet? - do you ever use non-rectangular sub-images? XXX Dec 24 (6 days ago) to me Hi Chris, We use texture packer a lot in the office, it's like a standard for cocos2d and cocos2d-x (and others), i'm sure you've heard about it. http://www.codeandweb.com/texturepacker Texture packer has a lot of export options, including one in JSON and some for cocos2d (plist, apple's xml). I've never been in the need to use non-rectangular textures, so i wouldn't mind too much about it. The only use that i can think about is cutting sprites into pieces, but that's a very specific use case. Thank you for letting me help, xxx Chris Campbell Dec 25 (5 days ago) Yes, I have heard of that one. It certainly seems to be the most common. However, I have another question. I have not really used any texture packing software, but I was under the impression that it allows you to easily switch between using packed textures, or just the regular textures, by using a slightly different piece of code to load them. For example, instead of loading textures from individual image files manually, you use some code which will automatically take them from a sub-section of a larger image file. But in either case, you have to specify to load "cat.png", or "dog.png" or something, and these cat/dog etc files originally exist as separate files before being packed. Would it not be possible to just use the original individual files with RUBE? It seems to me that the artists and level-creator people should not need to know about sprite sheets at all, because sprite sheets are a post-process to gain some efficiency of app size and performance before final distribution. In fact, it seems to me that it might be detrimental to have RUBE or other intermediate tools using the final format of the sprite sheets, because when something about the images is changed, the sheet must be repacked, and then reloaded by the other tools before they can continue using it. This would create an extra step for the tool chain that would not be necessary if other tools were using the original images. This is just a workflow question I guess. As I say, I am not familiar with this workflow, but I had assumed that texture-packing was something that would be easily switched on/off, and mostly off during development, then on for release. XXX Dec 26 (5 days ago) to me Well, that's a good point, but in every game that I've worked on we create the spritesheets and then use them on the tools, it's no big deal and it's pretty common. Do you know CocosBuilder? (open source, but only available for mac http://cocosbuilder.com/) It uses the generated spritesheets and let's you use the images inside it like they weren't in the spritesheet. About the code needed to use a spritesheet for cocos2d-x (cocos2d must be similar): // Get a singleton, no worries here :) CCSpriteFrameCache* spriteFrameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); // Load spritesheet into the frame cache spriteFrameCache->addSpriteFramesWithFile("numbers.plist"); // Get a sprite using a spritesheet's image name CCSprite* number = CCSprite::createWithSpriteFrameName("0.png"); // Should clean up spriteFrameCache here if we don't need the // spritesheet anymore, but not important. To load a texture named "0.png" without using spritesheets: CCSprite* number = CCSprite::create("0.png"); As you can see, the first method needs to load the plist with all the frame info and then the createWithSpriteFrameName method gets the frame from the cache and creates the sprite. The second needs the texture to be in the resource directory. People don't usually have the original spritesheets' images in the project resources, but only the spritesheets and metadata (plist). Changing between texture packaging and textures is not common and means finding in the code where you used the assets and change it from one method to the other. As long as RUBE uses the spritesheet metadata to refer to the sprite, changes should not be noticed for the user. I guess RUBE would need a refresh button to reload the spritesheets and actually see the new version in the editor. To be independent from the spritesheet, the Json the image should only contain the name of the spritesheet and the name of the image inside of the spritesheet; that would be enough to leave all the changes of the spritesheet out of the Json (except the raw opengl data, which seems quite redundant with spritesheets). Glad to help, XXX Chris Campbell Dec 26 (4 days ago) to XXX I see. Then I think it will definitely be necessary to support. I had assumed people would use project and pre-processor configurations to switch between using packed or regular textures. Thanks for the great info! XXX Dec 27 (3 days ago) to me For the games that i'm currently working on, spritesheets are the only way to go, otherwise the phones cannot handle too much textures in screen and debugging becomes a nightmare. I'm looking forward to see RUBE's next version! Thank you for letting me help, XXX