Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:32:47+00:00 2026-05-30T18:32:47+00:00

I have a class called Textures that use holds some data like this //Textures.h

  • 0

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.
Resources folder

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]];
        .......
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:32:48+00:00Added an answer on May 30, 2026 at 6:32 pm

    NSAsserts are a real pain , but when on top of it the message is useless 🙂 … ok, looking at line 192 in cocos2d (CCSprite), the texture is nil (causing the assert failure). Check to see if you got messages similar to these for your textures when adding them to the sharedTextureCache.

    2012-03-02 21:19:43.497 MyGame[55224:12203] cocos2d: CCTexture2D. Can’t create Texture. UIImage is nil

    2012-03-02 21:19:43.498 MyGame[55224:12203] cocos2d: Couldn’t add image:a.png in CCTextureCache

    If you did, the textures have not been found. Make certain they are in your resources folder, and also that they are members of the target you are building.

    part 2 : just re-reading your code, you would get the same error if SpriteTextures was nil in the statement

    [SpriteTextures setTextures];
    BalloonSprite = [Balloon spriteWithTexture: [SpriteTextures Balloon_RED]];
    

    That could explain why it works in one place but not the other.

    part 3 : you are not initializing nor setting SpritTextures in your class init. Try:

        self.isTouchEnabled = true;
        self.SpriteTextures = [[Textures alloc] init];
        [SpriteTextures setTextures];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a templated class called PooledResource . It handles loading things like textures
I have a class called Profile that has some simple properties and then it
I have a class called DatabaseHelper that wraps a DbConnection. What's the proper way
I have this class called Table: class Table { public string Name { get
i have this class called MemoryManager, it is supposed to implement a simple smart
I have a class called UserInfo that contains details about a given user. There
I have a class called Question that has a property called Type. Based on
I have a class called Image and a class that extends it called ImageSheet
So I have a subclass of Texture2D called ScrollingBackgroundTexture . I'd like to use
I have class called Chicken and in Chicken I have some methods, so in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.