Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 视网膜装置上的CCSpriteFrame直肠针_Ios_Objective C_Cocos2d Iphone_Retina - Fatal编程技术网

Ios 视网膜装置上的CCSpriteFrame直肠针

Ios 视网膜装置上的CCSpriteFrame直肠针,ios,objective-c,cocos2d-iphone,retina,Ios,Objective C,Cocos2d Iphone,Retina,我正在用下面的代码创建一个爆炸精灵动画,图像是440x440像素(一个110x110像素帧的4x4网格),带有880x880的-hd图像(正在视网膜设备上加载) 这是在非视网膜设备上 CCTexture *explosionTexture = [CCTexture textureWithFile:@"explosion.png"]; NSMutableArray *frames = [NSMutableArray array]; int frameCount = 0; for (int y =

我正在用下面的代码创建一个爆炸精灵动画,图像是440x440像素(一个110x110像素帧的4x4网格),带有880x880的-hd图像(正在视网膜设备上加载)

这是在非视网膜设备上

CCTexture *explosionTexture = [CCTexture textureWithFile:@"explosion.png"];
NSMutableArray *frames = [NSMutableArray array];
int frameCount = 0;
for (int y = 0; y < 4; y++) {
    for (int x = 0; x < 4; x++) {
        CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:explosionTexture
                                                  rectInPixels:CGRectMake(x*110, y*110, 110, 110)
                                                       rotated:NO
                                                        offset:CGPointZero
                                                  originalSize:CGSizeMake(440, 440)];
        [frames addObject:frame];
        frameCount++;
        if (frameCount == 14) break;
    }
}
2014-05-09 23:22:10.872 SimpleGame[4131:70b] x:0, y:0
2014-05-09 23:22:10.872 SimpleGame[4131:70b] frame.rect:{{0, 0}, {55, 55}}
2014-05-09 23:22:10.873 SimpleGame[4131:70b] x:1, y:0
2014-05-09 23:22:10.873 SimpleGame[4131:70b] frame.rect:{{55, 0}, {55, 55}}
2014-05-09 23:22:10.874 SimpleGame[4131:70b] x:2, y:0
2014-05-09 23:22:10.874 SimpleGame[4131:70b] frame.rect:{{110, 0}, {55, 55}}
2014-05-09 23:22:10.872 SimpleGame[4131:70b] x:0, y:0
2014-05-09 23:22:10.872 SimpleGame[4131:70b] frame.rect:{{0, 0}, {110, 110}}
2014-05-09 23:22:10.873 SimpleGame[4131:70b] x:1, y:0
2014-05-09 23:22:10.873 SimpleGame[4131:70b] frame.rect:{{110, 0}, {110, 110}}
2014-05-09 23:22:10.874 SimpleGame[4131:70b] x:2, y:0
2014-05-09 23:22:10.874 SimpleGame[4131:70b] frame.rect:{{220, 0}, {110, 110}}
文档确实说(名字很明显)
rectInPixels
是以像素(而不是点)为单位计算的。这是正确的吗?如果这看起来完全违反直觉,对我没有帮助,为什么不简单地计算分数呢?那么如何计算视网膜和非视网膜的正确直肠

这真的让我困惑,因为我敢肯定这是一个工作,是一天前,所有我已经改变,因为它是工作的是图像的尺寸


已经很晚了,所以我可能错过了一些非常明显的东西,但我似乎无法解决这个问题,所以任何帮助都将不胜感激

您记录的frame rect再次以点为单位,因此根据您的代码,这实际上是正确的。您缺少的是将像素大小乘以以创建视网膜纹理的实际像素坐标和大小:

CGFloat texScale = explosionTexture.contentScale;
CGRect rectInPixels = CGRectMake(x*110*texScale, y*110*texScale, 110*texScale, 110*texScale);

这是假设您有一个带有-hd后缀的2x缩放纹理(explosion hd.png)。如果您只有一张图像,上面的代码不会改变任何内容,因为您将在一个像素数为4倍的显示器上使用相同的纹理,因此该纹理看起来只有非视网膜设备上的一半大。

我不知道contentScale属性。我最终通过获取图像的实际像素值并使用它来绕过它<代码>int explosionWidth=explosionTexture.pixelWidth
CGRect rectInPixels=CGRectMake(x*(爆炸宽度/4),y*(爆炸高度/4),爆炸宽度/4,爆炸高度/4)