Which is the best way to get the main texture from the SPTextureAtlas class?
I want to pass it to a SPBitmapFont, and also use it for other images and avoid re-loading the PNG.
Which is the best way to get the main texture from the SPTextureAtlas class?
I want to pass it to a SPBitmapFont, and also use it for other images and avoid re-loading the PNG.
Hi!
Currently, the base texture of a texture atlas is not accessible -- you could, however, extend the class and add a property to receive it. (The member is named "mAtlasTexture".) That's one nice feature of Objective C =)
However, if you want to include your bitmap font in the texture atlas, you can do so directly -- just let the bitmap font texture be part of the texture atlas, and then initialize the bitmap font with the atlas (sub-)texture. (Use the method 'registerBitmapFontFromFile:texture:' and pass '[atlas textureByName:@"myFont"]' as second parameter).
Oh, the problem is that the utility that we made arranges all "sub-textures" to optimize the space. That is, it breaks all characters into single sub-textures each.
I'm new to Objective-C... But based on my knowledge of Java, a private member cannot be accesed by a derived class... I'll try to extend it tonight... If not, i think i'll have to modify sparrow, at least to put it as protected member.
Thanx.
Oh, i thing i got that last one...
I can create a big sub-texture that is equal to the size of all the texture atlas and use that for the font bitmap. Is there a performance penalty for this? I think there is not, but i have to be sure...
Ah, OK, now I understand your problem! Your glyphs are distributed between all other atlas textures, right? OK, then your approach is correct.
To access the texture, you don't need to create a subclass. Objective C has a feature called "Categories", which lets you open up an existing class and add features to it.
In your case, you'd have to create a new category for the SPTextureAtlas, like this:
File: SPTextureAtlas_Extension.h
#import "SPTextureAtlas.h"
@interface SPTextureAtlas (MyExtensionName)
@property (nonatomic, readonly) SPTexture *baseTexture;
@end
File: SPTextureAtlas_Extension.m
#import "SPTextureAtlas_Extension.h"
@implementation SPTextureAtlas (MyExtensionName)
- (SPTexture *)baseTexture
{
return mAtlasTexture;
}
@end
Now, you can use the property "baseTexture" just as if it had always been part of the class. All you have to do is import the h-file from above when you need the method.
And, BTW, the approach you mentioned in your last post should work, too -- it should not have a measurable performance impact.
Daniel
Wow, you are really helpful.
I've alredy implemented the "big texture", but i didn't liked it because i was creating it with a "random" name to avoid duplicates.
Very thanx for the code, i'll implement it right away.
You must log in to post.