Libgdx texture atlas vs files - file

So in my game i have more than 32000 images (size: 32x32). How to store this amount of images? What could better: loading these images as separate files or as one big texture atlas?

When you load a texture (image) in your game by doing you load a texture in GPU.
So let's say you have 3200 images and you load them separately that means 3200 textures loaded on the GPU. That's harsh and will eat loads of memory.
Now let me explain what is TextureRegion
TextureRegion, takes an area from the Texture according to the dimension you provide, the advantage of having it is that you don't have to load textures again and again and the bigger advantage is you don't have to load each and every texture on GPU as you can do it directly by loading one big texture and extracting sub regions(TextureRegions) from it.
Now because you want to use TextureRegions, it will be hard to know the dimensions of each and every sub image to load them from Texture Sheet. So what we do is we pack the Textures into a bigger Texture using TexturePacker(an application) which then creates a .pack file. It will pack every texture into one image AND create a .pack file. Now when you load the .pack file, it is loaded using TextureAtlas class
For example imagine a pokemon pack file which has all the pokemons into it.
TextureAtlas pokemonFrontAtlas = new TextureAtlas(Gdx.files.internal("pokemon//pokemon.pack"));
Now you packed 3200 files using Texture Packer and you want to load a image(Texture) which has file name as "SomePokemon".
Now to get a particular TextureRegion from it, you do
pokemonFrontAtlas.findRegion("SomePokemon")
findRegion(String name) returns you the textureRegion from the TextureAtlas.
A TextureAtlas class contains a collection of AtlasRegion class which extends TextureRegion class.
See Javadocs for more details
TextureAtlas

Related

Huge array of libSDL textures

I am developing an app that presents the user with a potentially very large user-generated image gallery, 10 or so images at the time.
The app is to be implemented in C using libSDL and 2D textures for accelerated rendering.
The overall gist of it in pseudocode is:
while cycle < MAX_CYCLES
while i < MAX_STEPS
show a gallery of 10 image thumbnails
while (poll events)
if event == user has pushed next
break
i++
scramble image galleries using a genetic algorithm
cycle++
I could load every image from disk at initialization time, creating all the required textures, so image presentation is fast. But of course this would be slow and potentially allocate a huge array of textures.
I will scale down the images for presentation, so this could mitigate the problem, but the total size of the collection depends on user preference. Surely I can cap the maximum value, but it cannot be small.
I was thinking about unloading every unused image at every step of every cycle, using SDL_FreeSurface and SDL_DestroyTexture. This would mean reloading the data from disk, recreating the surface and recreating the texture each time. Is this a viable approach?
Also I understand that SDL textures are stored in GPU memory, so the amount of available memory on the card should be my main concern. Am I right?
In summary, is there a recommended method to deal with this type of situation?
I would keep always 3 slides in memory.
Prev - Current - Next
While presenting the current slide, preload the next slide and unload the slide no (Current - 2).
Also I understand that SDL textures are stored in GPU memory, so the amount of available memory on the card should be my main concern. Am I right?
Not quite, if the GPU (Driver) seems it necessary, it will outsource unused texture data to RAM.
For Example, if you're presenting 10 Images and thus have 30 Images present in memory, then for 2K (with alpha) (1920 x 1080 x 4) you will need approx. 250 MB.
As long as you don't run on an embedded system (or very old, outdated system), this shouldn't be a big concern.

Big SCNGeometry SceneKit for iOS

I am working on a cocoa/iOS projet.
I have a common swift class which manage a Scenekit scene.
I want to draw a big terrain (about 5000x5000 points).
I have 2 triangles per 4 points. I have created a scngeometry object for the whole terrain (is it a good thing ?)
I decided to store those points in a 6-Float structure (x,y,z and r,g,b). I tried to create an empty array or to allocate a big array at the begining : i got the same issue.
I work with Int datatype for indices array.
The project works fine on Cocoa but i get memory errors on iOS. I think this is because of the need to have a big and contigous array for vertex.
I tried to create several chunks of geometry objects but scene kit does not like if we erase a previous buffer.
What is the best practice in this case ?
Is there a way to store vertex on the mass storage instead of memory arrays/buffers ?
Thanks
So...twice as many terrain points as there are pixels on a shiny new 5K display? That's a huge amount of memory to be using at once on iOS. And you won't be able to see that resolution on an iOS device.
So how about:
Break your 25 million pixel terrain into smaller tiles, each in its own SCNNode. Loop through the tiles, create one SCNNode, throw away the 6-Float array for that tile and move to the next.
Use SCNLevelOfDetail to produce much simpler versions of those nodes, for display when they're very far away.
Do the construction work on OS X. Archive your scene (NSSecureCoding). Bundle that scene into the iOS app.
Consider using reference nodes in your main SCNScene, and archive each tile as a separate SCNScene file.
Hopefully you're already using triangle strips, not triangles, to build your geometry.

AS3 : how can I store tiled map editor's data efficiently in an AS3 class

Please let me describe my question with details.
Lets say I will create a game with 500 different maps.
Each of these maps are containing 80x40 16px tiles.(unfortunately it's necessary to parse per 16px)
But in game , I'm gonna create 32px tiles per 4 16px tiles.
I store every embedded tmx file in a class with static methods.
Here is my question, which of the following 2 options I should chose;
1- Should I convert the tmx data into as3 data ( into an array which contains tiles' data) each time player enters a different map.
2- Should I convert all maps' data at the beginning of the game, then whenever player enters a different map, I directly take the array and create the map from it.
I am asking this because I'm not sure if it's a problem to keep 500 arrays with the size of 80x40. (would it tire ram too much? )
Option 1 is better.You can load map config data before you enter a map, and it's not necessary to store all config data in the memory, you can store 10 map config data which are recently used(like LRU cache algorithm).
In my experience, if your map config data is a xml,you can transfer it to a byteArray to reduce its size and decompress when loaded.

Many sprites need to load on mobile devices in unity3D

My 2D game has 3 characters which each character has 7 types of animation that is contained to many frames. Those are around 1050 frames (sprites) for all 3 characters animations. I make atlas by these sprites but right now it is around 60 2048x2048 atlases with compressed format.
So on some devices which I've tested, The game is not loaded but on some other devices it is. I think it's because of too many atlases which they can't load on these mobile devices RAM.
I've tried to make these frames as small as possible and put them in atlas but as I said before the number of atlases is 60 and I can't reduce number of frames or size of them more than this.
What do you think guys and what can I do ?
There is a limitation in mobile devices for how many images can load in ram. This is a bad idea to import your sprite with 2048*2048 dimension and then compress them to something like 512*512. You have to reduce the size of those sprite in an image editor program and then you can join 16 512*512 images and make a 2048*2048 sprite. Now you just load 1 image in mobile ram instead of 16 images.

Embedding loads of images

I got 42 images that I want to embed and then put on an array.
I tried to do it within a for loop, but it doesn't seem to work.
How exactly can I avoid to have 42 embed lines + a very long line for the array ?
The only way to embed multiple images without an embed line for each one is to use a Sprite Sheet (sometimes called a 'Texture Atlas', or simply a 'Sprite'). This will take a folder of images, and generate one large image. And also give you a data file (use XML or JSON) of all images in your folder and where they're positioned inside the Sprite Sheet.
You can then embed the Sprite Sheet once.
For this you need 2 things:
1/ Software to create your sprite sheet... There are many tools available, the one I use for example is Texture Packer: http://www.codeandweb.com/texturepacker
2/ An actionscript class or framework, designed to handle referencing images from your sprite sheet... This is a native feature of Starling, but if you're not ready to support Flash Player 11 then you can find some publicly available frameworks for this:
For example: Spriter: http://abeltoy.com/projects/spriterAS3/usage.html has a class called BitmapSpriter to handle sprite sheets natively in AS3.
You could use a for each loop.
var items:Array = ["hi", "there", "bob"];
for (var index in items) {
trace(index+" => "+items[index]); // traces "0 => hi", "1 => there" and "2 => bob"
}

Resources