编辑:下面的第一个答案我已经更多地查看了stackoverflow并将问题改为°我怎样才能使用唯一的HD文件?“,并发现这个:How do I stop Cocos2D from requiring standard definition resources (SD images)?我现在将尝试提出的解决方案和如果它的工作原理,我将离开这个编辑的标题,并删除可能是误导性的最初的问题。如何接近-hd文件
是我努力学习的Cocos2D和使用的书籍像cookbook和learn cocos2d一段时间。这些都是一个很好的开始,但有时我陷入像今天我会试图解释的那样的问题
我开始修改这个例子请参阅第166页的1书中的使用CCParallaxNode。我的目标是添加以下尺寸的四层:使用iOS 5.0和Cocos2d 1.01 RC库的iPhone模拟器上运行的960像素高和1280像素宽的窗口。
我没有用安装模板创建新项目和修改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运行代码,使用GIMP的alpha通道PNG图像创建。它一开始工作,现在不再了。我不确定我做了什么来搞砸。
奇怪的是,它与图像5它确实工作。
我已经检查过,并且UIImage规范有建议使用1024 x 1024图像的限制。所以我做了并重新调整了图像6并创建了图像3这是在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),伽玛保存,保存层移动
是的,文件名是一个愚蠢的错误..没有发现,但我意识到这个问题。我没有意识到的是,对于每个文件,我还需要非HD版本。我认为,如果我启用了视网膜显示并将-hd文件放入文件夹,那么Cocos2d会自动将标准显示文件中的-hd文件重新缩放。我确实创建了四个文件副本,并删除了-hd扩展名,并将其添加到项目中,然后再次运行,现在工作正常。我有一个类似的问题是Zwapotex纹理表,无法理解为什么没有工作。谢谢:) – mm24 2012-04-19 17:32:22
我同意,这似乎是一个愚蠢的要求,应该抛出一个更具体的错误至少。 – hspain 2012-04-19 17:53:56
..我不明白的是如何避免必须放置这两个文件。我有一个相当大的应用程序,我只针对视网膜显示设备,并不想通过创建低分辨率文件来增加应用程序的内存大小。有没有办法强制只有-hd文件?谢谢! :) – mm24 2012-04-19 18:17:07