2012-04-19 12 views
1

EDIT:私は最初の答えに続き、私はもっとstackoverflowを見て、どのように私はhdファイルを使用することができますか?との問題を言い換えました: "これを発見しました:How do I stop Cocos2D from requiring standard definition resources (SD images)?私は今、それが動作する場合、私は編集したタイトルを残して、誤解を招くかもしれない最初の質問を削除します。どのようにアプローチする-hdファイル

私はCocos2dを習得しようとするとcookbooklearn cocos2dのような本を使用していますことながら、である。これらは、素晴らしいスタートですが、時々私

私は今、説明しようとしているような問題に悩まされています。私の目標は、iOS 5.0を搭載したiPhoneシミュレータとCocos2d 1.01 rcライブラリで動作する960ピクセルの高さと1280ピクセルのサイズの4つのレイヤーを追加することです。

私がインストールされたテンプレートを使用して新しいプロジェクトを作成しましたし、次のようHelloWorldLayer.mクラスを変更:

// Import the interfaces 
#import "HelloWorldLayer.h" 

// HelloWorldLayer implementation 
@implementation HelloWorldLayer 
+(CCScene *) scene 
{ 
    // 'scene' is an autorelease object. 
    CCScene *scene = [CCScene node]; 

    // 'layer' is an autorelease object. 
    HelloWorldLayer *layer = [HelloWorldLayer node]; 

    // add layer as a child to scene 
    [scene addChild: layer]; 

    // return the scene 
    return scene; 
} 

// on "init" you need to initialize your instance 
-(id) init 
{ 
    // always call "super" init 
    // Apple recommends to re-assign "self" with the "super" return value 
    if((self=[super init])) { 

     CCSprite* parallaxLayer01 = [CCSprite spriteWithFile:@"0-hd-red.png"]; 
     CCSprite* parallaxLayer02 = [CCSprite spriteWithFile:@"0-hd-red.png"]; 
     CCSprite* parallaxLayer03 = [CCSprite spriteWithFile:@"0-hd-red.png"]; 
     CCSprite* parallaxLayer04 = [CCSprite spriteWithFile:@"0-hd-red.png"]; 

     /** 
     CCSprite* parallaxLayer01 = [CCSprite spriteWithFile:@"0-hd.png"]; 
     CCSprite* parallaxLayer02 = [CCSprite spriteWithFile:@"1-hd.png"]; 
     CCSprite* parallaxLayer03 = [CCSprite spriteWithFile:@"2-hd.png"]; 
     CCSprite* parallaxLayer04 = [CCSprite spriteWithFile:@"3-hd.png"];  
     **/ 

     /** 
     CCSprite* parallaxLayer01 = [CCSprite spriteWithFile:@"2-hd.png"]; 
     CCSprite* parallaxLayer02 = [CCSprite spriteWithFile:@"2-hd.png"]; 
     CCSprite* parallaxLayer03 = [CCSprite spriteWithFile:@"2-hd.png"]; 
     CCSprite* parallaxLayer04 = [CCSprite spriteWithFile:@"2-hd.png"];  

**/ 
     /** 
     CCSprite* parallaxLayer01 = [CCSprite spriteWithFile:@"bar.png"]; 
     CCSprite* parallaxLayer02 = [CCSprite spriteWithFile:@"bar.png"]; 
     CCSprite* parallaxLayer03 = [CCSprite spriteWithFile:@"bar.png"]; 
     CCSprite* parallaxLayer04 = [CCSprite spriteWithFile:@"bar.png"];  
     **/ 
     /** 
     CCSprite* parallaxLayer01 = [CCSprite spriteWithFile:@"bar-hd.png"];  
     CCSprite* parallaxLayer02 = [CCSprite spriteWithFile:@"bar-hd.png"]; 
     CCSprite* parallaxLayer03 = [CCSprite spriteWithFile:@"bar-hd.png"]; 
     CCSprite* parallaxLayer04 = [CCSprite spriteWithFile:@"bar-hd.png"];  
     **/ 

     //Create a parallax node and add all four sprites 
     CCParallaxNode* parallaxNode = [CCParallaxNode node]; 
     [parallaxNode setPosition:ccp(0,0)]; 
     [parallaxNode addChild:parallaxLayer01 z:1 parallaxRatio:ccp(0, 0) positionOffset:ccp(0,0)]; 
     [parallaxNode addChild:parallaxLayer02 z:2 parallaxRatio:ccp(1, 0) positionOffset:ccp(0,0)]; 
     [parallaxNode addChild:parallaxLayer03 z:3 parallaxRatio:ccp(2, 0) positionOffset:ccp(0,0)]; 
     [parallaxNode addChild:parallaxLayer04 z:4 parallaxRatio:ccp(3, 0) positionOffset:ccp(0,0)]; 
     [self addChild:parallaxNode z:0 tag:1]; 

     //Move the node to the left then the right 
     //This creates the effect that we are moving to the right then the left 
     CCMoveBy* moveRight = [CCMoveBy actionWithDuration:5.0f position:ccp(-80, 0)]; 
     CCMoveBy* moveLeft = [CCMoveBy actionWithDuration:2.5f position:ccp(80, 0)]; 
     CCSequence* sequence = [CCSequence actions:moveRight, moveLeft, nil]; 
     CCRepeatForever* repeat = [CCRepeatForever actionWithAction:sequence]; 
     [parallaxNode runAction:repeat]; 

    } 
    return self; 
} 

// on "dealloc" you need to release all your retained objects 
- (void) dealloc 
{ 
    // in case you have something to dealloc, do it in this method 
    // in this particular example nothing needs to be released. 
    // cocos2d will automatically release all the children (Label) 

    // don't forget to call "super dealloc" 
    [super dealloc]; 
} 
@end 

私は4を使用してコードを実行しようとしなかった、アルファチャンネル付きPNG画像はGIMPを使用して作成したが。それは最初はうまくいきましたが、今はもう動作しません。私が何をしぼったのか分かりません。

奇妙なことは画像あり5が効いていることです。

私は、1024×1024の画像を使用することを推奨するUIImage仕様に制限があります。画像6を作成して再スケーリングし、画像reduced image3を作成しましたが、これはUIImageで指定された制限内ですが動作しません。

2012-04-19 17:14:29.189 ParallaxNodeTest[3713:10a03] cocos2d: cocos2d v1.0.1 
2012-04-19 17:14:29.190 ParallaxNodeTest[3713:10a03] cocos2d: Using Director Type:CCDirectorDisplayLink 
2012-04-19 17:14:29.226 ParallaxNodeTest[3713:10a03] cocos2d: OS version: 5.1 (0x05010000) 
2012-04-19 17:14:29.227 ParallaxNodeTest[3713:10a03] cocos2d: GL_VENDOR: Apple Computer, Inc. 
2012-04-19 17:14:29.228 ParallaxNodeTest[3713:10a03] cocos2d: GL_RENDERER: Apple Software Renderer 
2012-04-19 17:14:29.229 ParallaxNodeTest[3713:10a03] cocos2d: GL_VERSION: OpenGL ES-CM 1.1 APPLE 
2012-04-19 17:14:29.229 ParallaxNodeTest[3713:10a03] cocos2d: GL_MAX_TEXTURE_SIZE: 4096 
2012-04-19 17:14:29.230 ParallaxNodeTest[3713:10a03] cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16 
2012-04-19 17:14:29.231 ParallaxNodeTest[3713:10a03] cocos2d: GL_MAX_SAMPLES: 4 
2012-04-19 17:14:29.233 ParallaxNodeTest[3713:10a03] cocos2d: GL supports PVRTC: YES 
2012-04-19 17:14:29.234 ParallaxNodeTest[3713:10a03] cocos2d: GL supports BGRA8888 textures: YES 
2012-04-19 17:14:29.235 ParallaxNodeTest[3713:10a03] cocos2d: GL supports NPOT textures: YES 
2012-04-19 17:14:29.235 ParallaxNodeTest[3713:10a03] cocos2d: GL supports discard_framebuffer: YES 
2012-04-19 17:14:29.235 ParallaxNodeTest[3713:10a03] cocos2d: compiled with NPOT support: NO 
2012-04-19 17:14:29.236 ParallaxNodeTest[3713:10a03] cocos2d: compiled with VBO support in TextureAtlas : YES 
2012-04-19 17:14:29.236 ParallaxNodeTest[3713:10a03] cocos2d: compiled with Affine Matrix transformation in CCNode : YES 
2012-04-19 17:14:29.237 ParallaxNodeTest[3713:10a03] cocos2d: compiled with Profiling Support: NO 
2012-04-19 17:14:29.268 ParallaxNodeTest[3713:10a03] cocos2d: surface size: 960x640 
2012-04-19 17:14:29.336 ParallaxNodeTest[3713:10a03] cocos2d: Filename(0-hd-red.png) contains -hd suffix. Removing it. See cocos2d issue #1040 
2012-04-19 17:14:29.337 ParallaxNodeTest[3713:10a03] cocos2d: CCFileUtils: Warning HD file not found: 0-red-hd.png 
2012-04-19 17:14:29.338 ParallaxNodeTest[3713:10a03] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil 
2012-04-19 17:14:29.339 ParallaxNodeTest[3713:10a03] cocos2d: Couldn't add image:0-red.png in CCTextureCache 
2012-04-19 17:14:29.340 ParallaxNodeTest[3713:10a03] cocos2d: Filename(0-hd-red.png) contains -hd suffix. Removing it. See cocos2d issue #1040 
2012-04-19 17:14:29.340 ParallaxNodeTest[3713:10a03] cocos2d: CCFileUtils: Warning HD file not found: 0-red-hd.png 
2012-04-19 17:14:29.341 ParallaxNodeTest[3713:10a03] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil 
2012-04-19 17:14:29.342 ParallaxNodeTest[3713:10a03] cocos2d: Couldn't add image:0-red.png in CCTextureCache 
2012-04-19 17:14:29.342 ParallaxNodeTest[3713:10a03] cocos2d: Filename(0-hd-red.png) contains -hd suffix. Removing it. See cocos2d issue #1040 
2012-04-19 17:14:29.343 ParallaxNodeTest[3713:10a03] cocos2d: CCFileUtils: Warning HD file not found: 0-red-hd.png 
2012-04-19 17:14:29.344 ParallaxNodeTest[3713:10a03] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil 
2012-04-19 17:14:29.345 ParallaxNodeTest[3713:10a03] cocos2d: Couldn't add image:0-red.png in CCTextureCache 
2012-04-19 17:14:29.345 ParallaxNodeTest[3713:10a03] cocos2d: Filename(0-hd-red.png) contains -hd suffix. Removing it. See cocos2d issue #1040 
2012-04-19 17:14:29.346 ParallaxNodeTest[3713:10a03] cocos2d: CCFileUtils: Warning HD file not found: 0-red-hd.png 
2012-04-19 17:14:29.365 ParallaxNodeTest[3713:10a03] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil 
2012-04-19 17:14:29.366 ParallaxNodeTest[3713:10a03] cocos2d: Couldn't add image:0-red.png in CCTextureCache 
2012-04-19 17:14:29.367 ParallaxNodeTest[3713:10a03] *** Assertion failure in -[CCParallaxNode addChild:z:parallaxRatio:positionOffset:], /Users/daniele/Desktop/ParallaxNodeTest/ParallaxNodeTest/libs/cocos2d/CCParallaxNode.m:91 
2012-04-19 17:14:29.369 ParallaxNodeTest[3713:10a03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Argument must be non-nil' 
*** First throw call stack: 
(0x19e2022 0x1f7ccd6 0x198aa48 0x11af2cb 0x40661 0xb588e 0x3ba25 0xb5632 0xb4d3e 0x8164be 0x817274 0x826183 0x826c38 0x81a634 0x279aef5 0x19b6195 0x191aff2 0x19198da 0x1918d84 0x1918c9b 0x816c65 0x818626 0xb4816 0x24b5 0x1) 

私は実行することが以前にできたように、画像サイズがここでの問題はないと思われるが、それが動作するという事実:私は次のエラーメッセージとコードがクラッシュするという意味では動作しないために

画像が5で、他の画像ではない6は、GIMPを使ってPNGファイルをどのように作成したかと私に何かを示唆しています。

接着剤はありますか? 、解像度を保存する作成日付を保存し、コメントを保存しての値を保存し、背景として 保存色:

太い上:私はGIMPのスクリーンショットは、私が(英語では、以下の翻訳を提供するわけではない)を使用しています4を設定付けます透明なドットの色。

thickedない: Interlacment(ADAM7)、ガンマを保存し、網膜の画像を使用するために層の動き

settings

bar badimage

答えて

1

を保存し、あなたは-hdの両方を含める必要がありますし、あなたのプロジェクトに非hdファイル必ずしも適切なサイズである必要はありませんが、どちらも存在する必要があります。

0-red.pngというファイルを使用する場合は、0-red.png0-red-hd.pngを含める必要があります。また、ファイル名の最後に-hdがあるように注意してください。

+0

ええ、ファイル名は愚かな間違いでした..それを見つけられませんでしたが、私は問題を認識していました。私が気付いていなかったことは、各ファイルに対して、私は非-hdバージョンも必要とすることです。網膜ディスプレイを有効にして-hdファイルをそのフォルダに置くと、Cocos2dは自動的に標準の表示ファイルに-hdファイルを再スケーリングすると思っていました。私はファイルの4つのコピーを作成し、-hd拡張子を削除し、プロジェクトに追加してから、もう一度実行して、今作業します。素晴らしいです。私はZwapotexのテクスチャシートを似たような問題を抱えていましたが、なぜ動作しなかったのか理解できませんでした。ありがとう:) – mm24

+2

私は同意する、それはより具体的なエラーを投げなければならない愚かな要件と思われる。 – hspain

+0

..どちらのファイルを置かなくてもいいかわかりません。私はかなり大きなアプリケーションを持っており、私は網膜ディスプレイデバイスだけをターゲットにしており、低解像度のファイルを作成することによってアプリケーションのメモリサイズを増やす必要はありません。 -hdファイルのみを強制的に使用する方法はありますか?ありがとう! :) – mm24

関連する問題