I have a class called Textures that use holds some data like this
//Textures.h
#import <Foundation/Foundation.h>
@interface Textures
{
CCTexture2D *Balloon_RED;
CCTexture2D *Balloon_POP;
}
@property (nonatomic, retain) CCTexture2D* Balloon_RED;
@property (nonatomic, retain) CCTexture2D* Balloon_POP;
-(void)setTextures;
+(CCTexture2D*) cacheImg: (NSString*) image;
@end
//Textures.m
#import "Textures.h"
@implementation Textures
@synthesize Balloon_RED;
@synthesize Balloon_POP;
-(void)setTextures
{
Balloon_RED = [Textures cacheImg:@"red.png"];
Balloon_POP = [Textures cacheImg:@"pop.png"];
}
+(CCTexture2D*)cacheImg: (NSString*)image
{
return [[CCTextureCache sharedTextureCache] addImage:image];
}
@end
And I use it in my main class like this: (SpriteTextures is of type "Textures" and BalloonSprite is of type "Balloon" which is my subclass of CCSprite)
[SpriteTextures setTextures];
BalloonSprite = [Balloon spriteWithTexture: [SpriteTextures Balloon_RED]];
After the splash screen loads I get an error saying its an invalid texture I'm using:
Assertion failure in -[Balloon initWithTexture:], /Users/Mark/Kobold2D/Kobold2D-1.0.5/__Kobold2D__/libs/cocos2d-iphone/cocos2d/CCSprite.m:192
2012-03-02 20:00:18.011 Game-iOS[1341:1ca03] ERROR: Uncaught exception Invalid texture for sprite
2012-03-02 20:00:18.011 Game-iOS[1341:1ca03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid texture for sprite'
Additional Info is that I'm using Kobold as you can see in the error log but that shouldn't really make a difference I'm sure I'm probably doing something wrong somewhere.
Any help is appreciated, thanks!
Edit
What the resources folder looks like, they are also in folders of the physical drive too.
Also, this works just fine (adding the texture2ds to main class)
Texture_RED = [[CCTextureCache sharedTextureCache] addImage:@"red.png"];
Texture_POP = [[CCTextureCache sharedTextureCache] addImage:@"pop.png"];
BalloonSprite = [Balloon spriteWithTexture: Texture_RED];
Or really, overall, is there a better way to organize a lot of sprites (that many need to change texture) for a game with close to 100 different images?
Edit
Main Class (*.h)
#import "Textures.h"
@interface MainClass : CCLayer
{
Textures *SpriteTextures;
}
-(void)loop;
@property (retain) Textures *SpriteTextures;
Implementation
-(id) init
{
if ((self = [super init]))
{
self.isTouchEnabled = true;
[SpriteTextures setTextures];
BalloonSprite = [Balloon spriteWithTexture: [SpriteTextures Balloon_RED]];
.......