tags:

views:

345

answers:

1

Hi, I am trying to use a nine patch image as a background in an android game. The image expands well in multiple resolutions but, my game has slowed down by 10 fps. I used to get a consistent 45 to 50 fps now I get 35 fps.

The question is when we use a nine patch as a drawable and set it as a background in a view does it have any performance implications as opposed to a plain bitmap drawing.

Thanks in advance.

+1  A: 

The question is when we use a nine patch as a drawable and set it as a background in a view does it have any performance implications as opposed to a plain bitmap drawing.

If you are causing it to be stretched, then yes.

CommonsWare
Thanks for the reply. Do you know why there is a performance drop ? Does the framework do the stretch and draw for every frame ? is this a bug or designed that way ? I hate to increase the app size by dropping in same images in different folders to support multiple resolutions.
wysiwyg
"Do you know why there is a performance drop?" Because stretching isn't free. "Does the framework do the stretch and draw for every frame?" I have no way to answer this, since I am not you, and therefore I did not write your code that is applying the nine-patch. "is this a bug or designed that way?" I am fairly certain that nine-patch images are not designed with games in mind. They are designed for use as backgrounds of `Button` and `EditText` widgets, not to be drawn on a `Canvas` or whatever it is that you are doing.
CommonsWare
"I hate to increase the app size by dropping in same images in different folders to support multiple resolutions." Nine-patch graphics are not meant to solve the problem of multiple resolutions. Nine-patch graphics are meant to solve the problem of widget backgrounds, which can have arbitrary dimensions.
CommonsWare
Thanks again for the quick reply.Bottom line : nine patches are not for game backgrounds or to support multiple resolutions.I have no other choice but to use different images for different resolutions.
wysiwyg
@wysiwyg: For games, yes. This is just another one of those places, as with memory allocations, where a game developer has to make sacrifices in the interests of fps. Other developers less constrained by this need don't have the same sorts of challenges. Sorry!
CommonsWare