Android Question Sprite Sheet, Imageview, and Animation Library

MarcTG

Active Member
Licensed User
Longtime User
Hi Erel
I probably have to look more into GameView to learn how to use it.
I am already using libgdx in my app (a live wallpaper) which I can also use to load my animations in the activity/settings... but I was looking for something simpler to load small animations in the settings using a sprite sheet. Is that possible?

Thanks
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
A spritesheet is not a good solution when you use a Canvas-based library, even with a library using the hardware acceleration because you will have to indicate a source rectangle for each frame to crop, which is costly. On a Nexus 7, for example, displaying the same image from a spritesheet (with DrawBitmap of the Accelerated Surface lib, which calls the same function than the GameView and Game Sprite libs) and from its own file (with DrawBitmapAt that does no cropping) shows a significant difference of performance: 34 fps instead of 42 in my test. So I recommend to split the sheet to have one file per frame or crop the spritesheet into an array of bitmaps before beginning to render. In both cases, you will have to use the Accelerated Surface lib to see the improvement.
With libGDX, it's completely different because of optimizations done (each region of a texture is not considered as a new texture, so there's no texture switch, and all renderers use batchs, which minimize the changes of OpenGL states). On the Nexus 7, the same test than above runs at constant 60 fps.
 
Last edited:
Upvote 0

MarcTG

Active Member
Licensed User
Longtime User
A spritesheet is not a good solution when you use a Canvas-based library, even with a library using the hardware acceleration because you will have to indicate a source rectangle for each frame to crop, which is costly. On a Nexus 7, for example, displaying the same image from a spritesheet (with DrawBitmap of the Accelerated Surface lib, which calls the same function than the GameView and Game Sprite libs) and from its own file (with DrawBitmapAt that does no cropping) shows a significant difference of performance: 34 fps instead of 42 in my test. So I recommend to split the sheet to have one file per frame or crop the spritesheet into an array of bitmaps before beginning to render. In both cases, you will have to use the Accelerated Surface lib to see the improvement.
With libGDX, it's completely different because of optimizations done (each region of a texture is not considered as a new texture, so there's no texture switch, and all renderers use batchs, which minimize the changes of OpenGL states). On the Nexus 7, the same test than above runs at constant 60 fps.

Hey Fred, thanks for the advice :)

For animation, I wanted to use a sprite sheet to to organize my content and just have 1 file per animation instead of manage multiple files for each...I intend to have one small animation per layout which would serve more like my own in-app advertisement and not content that I am worried about optimizing for performance.

As far as displaying an image from a sprite sheet, say I am using a certain image that is in a sprite sheet in my libgdx LWP, I want to display that same image in my settings without having to add a separate file in my assets. Can this be done without using Gameview, Libgdx, etc...

FYI, I am currently using your animation plus library for this type of animation with individual files per frame... When I wanted to implement this, I only had a couple of hours to make the animation and add it to my apk, I checked the forum for examples and I found yours to be the simplest and easiest... it didn't take much time to understand and implement. So again, thanks for providing all those libraries and examples :)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
how bad does drawbitmap perform compared to drawbitmap on the accelerated one?

I did some tests with it and it ran smooth enough but I didn't have 50 smileys like in your test just a few moving thing on top of a bitmap background that gets "redrawn" aswell.

Edit: this was on my Galaxy Apolly I5800 phone running on 2.2 and I'm not sure it supports the open gl stuff.
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Longtime User
how bad does drawbitmap perform compared to drawbitmap on the accelerated one?
You mean "with and without the hardware acceleration" ? If I run the Perf_Smiley demo on a Kindle Fire with settings 15/300, I get 45 fps with HA=True and 17 fps with HA=false.

I did some tests with it and it ran smooth enough but I didn't have 50 smileys like in your test just a few moving thing on top of a bitmap background that gets "redrawn" aswell.

Edit: this was on my Galaxy Apolly I5800 phone running on 2.2 and I'm not sure it supports the open gl stuff.
I cannot answer for the device (I don't know it), but Froyo supports OpenGL. Unfortunately, it cannot benefit from hardware acceleration and has some performance issues with canvas-based libraries so I strongly recommend to use libGDX if you want to get decent results with this Android version. Of course, if your game or animation needs only to animate 3 small sprites, all libraries will do the job.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Hey Fred, thanks for the advice :)

For animation, I wanted to use a sprite sheet to to organize my content and just have 1 file per animation instead of manage multiple files for each...I intend to have one small animation per layout which would serve more like my own in-app advertisement and not content that I am worried about optimizing for performance.

As far as displaying an image from a sprite sheet, say I am using a certain image that is in a sprite sheet in my libgdx LWP, I want to display that same image in my settings without having to add a separate file in my assets. Can this be done without using Gameview, Libgdx, etc...

FYI, I am currently using your animation plus library for this type of animation with individual files per frame... When I wanted to implement this, I only had a couple of hours to make the animation and add it to my apk, I checked the forum for examples and I found yours to be the simplest and easiest... it didn't take much time to understand and implement. So again, thanks for providing all those libraries and examples :)
If you want to animate your spritesheet with AnimationPlus, you have to create an array of bitmaps from the loaded file by using the Crop function of the Accelerated Surface lib.
EDIT: this solution can be memory hungry as you load the spritesheet in memory then all frames from it.
 
Last edited:
Upvote 0
Top