このようなデータを保持する Textures というクラスがあります
//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
そして、私はそれをメインクラスで次のように使用します: ( SpriteTexturesは「Textures」タイプで、BalloonSpriteはCCSpriteのサブクラスである「Balloon 」タイプです)
[SpriteTextures setTextures];
BalloonSprite = [Balloon spriteWithTexture: [SpriteTextures Balloon_RED]];
スプラッシュ スクリーンがロードされた後、使用しているテクスチャが無効であるというエラーが表示されます。
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'
追加情報は、エラー ログでわかるように、私は Kobold を使用していることですが、実際には違いはありません。おそらくどこかで何か間違ったことをしていると確信しています。
どんな助けでも大歓迎です、ありがとう!
リソースフォルダーがどのように見えるかを
編集します。それらは物理ドライブのフォルダーにもあります。
また、これは問題なく機能します(メインクラスに texture2ds を追加)
Texture_RED = [[CCTextureCache sharedTextureCache] addImage:@"red.png"];
Texture_POP = [[CCTextureCache sharedTextureCache] addImage:@"pop.png"];
BalloonSprite = [Balloon spriteWithTexture: Texture_RED];
それとも、全体として、100 近くの異なる画像を含むゲームのために、多くのスプライト (テクスチャを変更する必要があるもの) を整理するためのより良い方法はありますか?
編集
メインクラス (*.h)
#import "Textures.h"
@interface MainClass : CCLayer
{
Textures *SpriteTextures;
}
-(void)loop;
@property (retain) Textures *SpriteTextures;
実装
-(id) init
{
if ((self = [super init]))
{
self.isTouchEnabled = true;
[SpriteTextures setTextures];
BalloonSprite = [Balloon spriteWithTexture: [SpriteTextures Balloon_RED]];
.......