File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change 3333#import " CCSpriteFrameCache.h"
3434
3535@implementation CCSpriteFrame
36+ {
37+ __weak CCTexture *_lazyTexture;
38+ }
39+
3640@synthesize textureFilename = _textureFilename;
3741@synthesize rotated = _rotated;
3842
@@ -137,15 +141,18 @@ -(void) setTexture:(CCTexture *)texture
137141 }
138142}
139143
140- -(CCTexture*) texture
144+ -(CCTexture *) lazyTexture
141145{
142- if ( _texture )
143- return _texture;
144-
145- if ( _textureFilename )
146- return [[CCTextureCache sharedTextureCache ] addImage: _textureFilename];
146+ CCTexture *texture = _lazyTexture;
147+ if (!texture && _textureFilename){
148+ _lazyTexture = texture = [[CCTextureCache sharedTextureCache ] addImage: _textureFilename];
149+ }
150+
151+ return texture;
152+ }
147153
148- // no texture or texture filename
149- return nil ;
154+ -(CCTexture*) texture
155+ {
156+ return (_texture ?: self.lazyTexture );
150157}
151158@end
You can’t perform that action at this time.
0 commit comments