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 33
33
#import " CCSpriteFrameCache.h"
34
34
35
35
@implementation CCSpriteFrame
36
+ {
37
+ __weak CCTexture *_lazyTexture;
38
+ }
39
+
36
40
@synthesize textureFilename = _textureFilename;
37
41
@synthesize rotated = _rotated;
38
42
@@ -137,15 +141,18 @@ -(void) setTexture:(CCTexture *)texture
137
141
}
138
142
}
139
143
140
- -(CCTexture*) texture
144
+ -(CCTexture *) lazyTexture
141
145
{
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
+ }
147
153
148
- // no texture or texture filename
149
- return nil ;
154
+ -(CCTexture*) texture
155
+ {
156
+ return (_texture ?: self.lazyTexture );
150
157
}
151
158
@end
You can’t perform that action at this time.
0 commit comments