Tag: sktexture

用于animateWithTextures的纹理迷路了。 有些框架显示红色X.

我的xCode项目有以下… AppDelegate中 GameViewController OpeningScene MainMenuScene GameScene 当游戏开始时,AppDelegate创build一个包含所有纹理的数组,我将使用… [self.texturesArray addObject:[SKTexture textureWithImageNamed:@"Background05.jpg"]]; 有大约120个纹理。 然后我预先使用… [SKTexture preloadTextures:self.texturesArray withCompletionHandler:^{ NSLog(@"************ Finished Preloading Textures in AppDelegate.m *************"); [[STGD sharedGD].currentScene presentMainMenuScene]; }]; 然后,我提出的OpeningScene,等待上述完成处理程序告诉它显示主菜单。 这是问题… 在主菜单(animateWithTextures)中使用预加载纹理的一个animation。 有时某些框架丢失,并以红色的X表示,通常表示无法find的文件。 如果发生这种情况,则总是会发生以下情况:切换到游戏场景时使用相同的animation(虽然GameScene中的animation尺寸较大),并且相同的帧将会丢失并显示红色的X.一个MainMenuScene和一个GameScene(每次重新创build每个场景)和相同的框架将会消失,直到我重新启动应用程序。 我知道纹理正在代码中正确创build,因为大部分时间它工作正常。 但是在15个结果中有一个发生了一些animation纹理丢失。 而每次发生时,都不会有相同的帧,甚至是相同数量的帧。 如果这意味着什么,它们也不是相邻的框架:P 在我开始使用预加载之前,我不相信这发生过。 但没有预加载我的最初fps是垃圾。 欣赏任何见解! 谢谢! 更新: 这里是我如何填充Star.m中的纹理数组。 Star对象用于MainMenuScene和GameScene self.animationSlides = [NSMutableArray arrayWithCapacity:45]; for (int i = 0; i < 45; i++) […]

SpriteKit:使用SKTextureAtlas会导致不正确的Physics Body

我正在构build我的第一个精灵套件游戏,最近阅读了一篇文章,说使用SKTextureAtlas来提高性能。 所以我把我所有的精灵图像都转移到了有组织的.atlas文件夹中,并相应地更新了代码。 不过,现在我的精灵怪异的物理机构(主要是过度扩大) 。 例如,我的玩家精灵有三个状态:飞(平),飞起来,飞下来。 这三个图像是非常相似的,有轻微的变化(arm平放,上,下) 。 在迁移到纹理图集之前,物理图像与图像相关。 然而,现在它比图像大得多,在y轴上略微拉伸。 这是我的player.atlas文件结构: 玩家飞iphone.atlas: player-flying-down@2x.png player-flying-down@3x.png player-flying-up@2x.png player-flying-up@3x.png player-flying@2x.png player-flying@3x.png 下面是我的代码示例: (Player是一个子类SKSpriteNode) let textureAtlas = SKTextureAtlas(named: "player-iphone") let playerFlyingTexture = textureAtlas.textureNamed("player-flying") let player = Player(texture: playerFlyingTexture, color: UIColor.clearColor(), size: CGSizeMake(100.0, 100.0)) let physicsBody = SKPhysicsBody(texture: playerFlyingTexture, size: CGSizeMake(100.0, 100.0)) physicsBody.dynamic = true physicsBody.affectedByGravity = true physicsBody.usesPreciseCollisionDetection = false […]

尝试仅使用textureTexture中的textureWithRect来使用SKTexture的一部分

我正在做的是基于完整的形象创build一个SKTexture SKTexture *fullTexture = [SKTexture textureWithImageNamed:@"fullImage"]; 我想使用fullTexture的全部宽度,但只有纹理的一部分高度,但是,从完整图像的TOP开始。 弄清楚宽度似乎是在百分比,我用下面的代码: SKTexture *croppedTexture = [SKTexture textureWithRect: CGRectMake(0,0,1,percentageY) 有人可以给我正确的CGRectMake的浮点数,从左上开始,从Y开始,只有一部分(固定的点数/像素) 或者以另一种方式来实现我想要做的事情? 谢谢 用我需要的可见示例更新了问题:

SKTexture得到图像名称

有没有可能从SKSpriteNode从SKTexture获取当前的图像名称? 我是SpriteKit中的新成员,我在写一个小游戏。 我需要侦测忍者什么时候会击中敌人。 像这样的东西 我正在做SKAction – (void)setUpHit { SKTextureAtlas *hitAtlas = [SKTextureAtlas atlasNamed:@"Ninja_hit"]; SKTexture *hit1 = [hitAtlas textureNamed:@"Ninja_hit_1"]; SKTexture *hit2 = [hitAtlas textureNamed:@"Ninja_hit_2"]; SKTexture *hit3 = [hitAtlas textureNamed:@"Ninja_hit_3"]; SKTexture *hit4 = [hitAtlas textureNamed:@"Ninja_hit_4"]; SKAction *hitAnimation = [SKAction animateWithTextures:@[hit1, hit2, hit3, hit4] timePerFrame:0.1]; SKAction *wait = [SKAction waitForDuration:0.3]; SKAction *goBack = [SKAction animateWithTextures:@[hit1, [SKTexture textureWithImageNamed:@"Ninja"]] timePerFrame:0.1]; […]

我应该在纹理工具包中的属性caching纹理?

我在我的游戏中使用图像资源的地图集。 我使用SKTextureAtlas preloadTextureAtlases在我的游戏场景开始时预加载了所有的地图集,这在我开始使用时有了很大的改变。 这是我的问题: 我应该为每一个纹理创build一个属性,一次又一次地产生怪物或皮卡精灵? 或者是完全不必要的开销,因为我在我的游戏场景中预载我的图集? 下面是一个怪物类中的两个非常简单的例子。 caching纹理: – (id)initWithSize:(CGSize)size { if (self = [super init]) { SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:monsterAtlas]; self.monsterFighterTexture = [atlas textureNamed:@"monster-fighter"]; } return self; } – (Monster *)monster { Monster * monster = [Monster spriteNodeWithTexture:self.monsterFighterTexture]; return monster; } 不要caching纹理。 – (Monster *)monster { SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:monsterAtlas]; […]

SKTexture预加载

当使用spritekit preloadTextures函数预加载纹理时,它会将提供的数组中的所有纹理一次加载到内存中。 如果你没有能力通过“加载屏幕”来分割游戏中的关卡,但是不同的图像文件有不同的关卡,那么怎样才能避免将所有图像一次存储在内存中而不会牺牲帧spritekit在需要时加载图像的速度?