Ios 纹理图集中的纹理未加载或显示
出于某些奇怪的原因,我的纹理图集中的纹理没有加载。我不知道为什么 下面是我通常如何声明/编码纹理Ios 纹理图集中的纹理未加载或显示,ios,objective-c,sprite-kit,sktexture,texture-atlas,Ios,Objective C,Sprite Kit,Sktexture,Texture Atlas,出于某些奇怪的原因,我的纹理图集中的纹理没有加载。我不知道为什么 下面是我通常如何声明/编码纹理 -(SKSpriteNode *)background { SKSpriteNode *background; NSArray *backgroundIpad; background = [SKSpriteNode spriteNodeWithImageNamed:@"dodgR - main background"]; background.position = CGP
-(SKSpriteNode *)background {
SKSpriteNode *background;
NSArray *backgroundIpad;
background = [SKSpriteNode spriteNodeWithImageNamed:@"dodgR - main background"];
background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
background.size = CGSizeMake(1136, 640);
NSArray *backgroundIphone = @[[SKTexture textureWithImageNamed:@"dodgR - animation 1.jpg"],
[SKTexture textureWithImageNamed:@"dodgR - animation 2.jpg"],
[SKTexture textureWithImageNamed:@"dodgR - animation 3.jpg"],
[SKTexture textureWithImageNamed:@"dodgR - animation 4.jpg"],
[SKTexture textureWithImageNamed:@"dodgR - animation 5.jpg"],
[SKTexture textureWithImageNamed:@"dodgR - animation 6.jpg"],
[SKTexture textureWithImageNamed:@"dodgR - animation 7.jpg"],
[SKTexture textureWithImageNamed:@"dodgR - animation 8.jpg"],
[SKTexture textureWithImageNamed:@"dodgR - animation 9.jpg"],
[SKTexture textureWithImageNamed:@"dodgR - animation 10.jpg"]];
SKAction *backgroundIphoneAnimation = [SKAction animateWithTextures:backgroundIphone timePerFrame:0.05];
SKAction *backgroundIphoneRepeat = [SKAction repeatActionForever:backgroundIphoneAnimation];
[background runAction:backgroundIphoneRepeat];
background.name = @"background";
return background;
}
我的纹理图集的名称是sprites.atlas
任何帮助都将不胜感激,谢谢您的上述代码仅在使用纹理图集以外的图像时有效,因为它实际上没有使用纹理图集 如果不使用SKTextureAtlas,就无法从地图册(据我所知)中提取图像。所以你不能直接抓取这些图像 斯威夫特:
let atlas = SKTextureAtlas(named: "BackgroundImages") // atlas name
var backgroundFrames = [SKTexture]()
let imageCount = atlas.textureNames.count
for var i=1; i<= imageCount/2; i++ {
let textureName = "dodgR - animation \(i)"
backgroundFrames.append(atlas.textureNamed(textureName))
}
let atlas=SKTextureAtlas(名为:“BackgroundImages”)//atlas名称
var backgroundFrames=[SKTexture]()
让imageCount=atlas.TextureName.count
对于var i=1;iTry从图像名称中删除.jpg。如果这没有帮助,请删除模拟器的内容和设置/从设备中删除应用程序,然后重新构建并运行。你认为“不加载”是什么?您是否看到丢失的资源图像(白色图像加红色X)或其他情况?另外,您的背景节点是否已正确添加到场景中?所有节点都包含红色X。删除.jpg没有帮助纹理唯一出现在屏幕上的时间是当它们不在atlasI中时。我没有太多地关注您的代码,而是关注您遇到的问题。。。因此,正如Beau Young所说,您必须在代码中正确使用地图集才能从中加载图像。
SKTextureAtlas *atlas = [SKTextureAtlas named:@"BackgroundImages"]; // atlas name
NSMutableArray *backgroundFrames = [NSMutableArray new];
int imageCount = atlas.textureNames.count;
for (int i = 1; i <= imageCount/2; i++) {
NSString *textureName = @"dodgR - animation \(i)";
[bacgroundFrames addObject:[atlas textureNamed:textureName]];
}