Tag: 精灵套件

如何为在xcode中使用swift制作的spritekit游戏创build主菜单?

我使用spritekit和swift在xcode中创build了一个非常简单的游戏。 我已经完成了编码实际的游戏本身。 现在我想创build一个主菜单,当游戏打开的时候,会有一个button的菜单进入设置或开始游戏。 我不知道如何做到这一点。 我应该使用故事板吗? 如果是这样,我怎么能在xcode中实现它。 感谢大家 :)

在迅速如何更改SKSpriteNode的颜色?

我创build了一个SKSpriteNode为黑色的游戏,当用户触摸屏幕时,我希望SKSpriteNode变成白色。 我search了一切可能的东西,尝试了很多不同的策略,但都没有运气。 有谁知道如何做到这一点? 这里是我的场景的代码: var blackBird = SKSpriteNode() override func didMoveToView(view: SKView) { //Black Bird var blackBirdTexture = SKTexture(imageNamed:"blackbird") blackBirdTexture.filteringMode = SKTextureFilteringMode.Nearest blackBird = SKSpriteNode(texture: blackBirdTexture) blackBird.setScale(0.5) blackBird.position = CGPoint(x: self.frame.size.width * 0.35, y: self.frame.size.height * 0.6) blackBird.physicsBody = SKPhysicsBody(circleOfRadius:blackBird.size.height/2.0) blackBird.physicsBody!.dynamic = true blackBird.physicsBody!.allowsRotation = false self.addChild(blackBird) } override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) […]

Sprite Kit – SKShapeNodepath不绘制四曲线

我一直在研究苹果新的Sprite Kit,并且一直在使用它。 然而,当我试图绘制一个SKShapeNode的曲线path时遇到了一个问题。 它似乎只是画一条直线。 这是一个非常简单的例子,我正在尝试绘制一个CGPath的SKShapeNode : CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddQuadCurveToPoint(path, NULL, 50, 100, 100, 0); CGPathAddLineToPoint(path, NULL, 50, -100); CGPathCloseSubpath(path); SKShapeNode *shape = [[SKShapeNode alloc]init]; shape.path = path; [self addChild:shape]; CGPathRelease(path); 这是我的ASCII艺术(对不起,我没有足够的声望发布一个实际的图像呢): ——————————————————————————— | EXPECTED RESULT | ACTUAL RESULT | ——————————————————————————— | | | | __—-__ | | | / […]

在SpriteKit游戏中拖动拖动

我正在做一个简单的SpriteKit游戏(在Swift中)和基本的物理,其中涉及拖放一些SKSpriteNodes与触摸。 该实现使用touchesBegan,touchesMoved等来更新所触摸的精灵的位置。 一切都按预期工作,但是: 好:游戏总共运行在60fps,CPU使用率在50%左右,CPU在6% 不好:被拖动的精灵有时非常不连贯(看起来像10fps或类似)。 请注意,我的意思是,即使在这个问题中,所有其他的精灵仍然以60fps的速度animation。 这是因为touchesMoved有时比平常每秒钟60次更less被调用。 通常我可以顺利拖放几个精灵,然后开始震荡,永远不会恢复正常。 这是我的触摸处理的简化版本: override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) { if let allTouches = touches.allObjects as? UITouch[] { for touch in allTouches { let draggedThing = findDraggedThingForTouch(touch) draggedThing.dragJoint!.bodyB.node.position = touch.locationInNode(self) } } } 我尝试过使用手势识别器而不是触摸事件,改变精灵的位置,而不是通过弹簧关节来拖动它,并且拖动的东西不是dynamic的。 所有版本都会出现相同的错误,即一段时间后,touchesMoved或手势识别器动作开始像每秒5次而不是60次。 什么可能导致这个?

用SpriteKitanimation可以画出一条线吗?

我想从苹果SpriteKit框架中让我们说A(100,50)到B(250,450)。 到目前为止,我能够使用SKShapeNode绘制这条线,并设置其path属性。 我想要实现的是画这条线。 可以说,从A点到B点画线需要2秒钟的时间。 我看着SKAction类,但似乎没有任何方法默认支持此function。 这是我用来创build该行的代码: CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 100, 50); CGPathAddLineToPoint(path, NULL, 250.0, 450.0); SKShapeNode *line = [SKShapeNode node]; line.path = path; [line setStrokeColor:[UIColor whiteColor]]; [self addChild:line]; 任何人都可以指向正确的方向吗?

SpriteKit内存pipe理预加载caching和fps问题

我的问题非常简单,根据苹果文档,您可以在呈现如下场景之前将纹理预加载到RAM中: SKTextureAtlas * atlas = [SKTextureAtlas atlasNamed:@"effect_circle_explode"]; SKTextureAtlas * atlas2 = [SKTextureAtlas atlasNamed:@"box_explodes"]; SKTextureAtlas * atlas3 = [SKTextureAtlas atlasNamed:@"fence_new"]; SKTextureAtlas * atlas4 = [SKTextureAtlas atlasNamed:@"swipe"]; SKTextureAtlas * atlas5 = [SKTextureAtlas atlasNamed:@"coin"]; SKTextureAtlas * atlas6 = [SKTextureAtlas atlasNamed:@"two_times"]; SKTextureAtlas * atlas7 = [SKTextureAtlas atlasNamed:@"three_times"]; SKTextureAtlas * atlas8 = [SKTextureAtlas atlasNamed:@"gus"]; [SKTextureAtlas preloadTextureAtlases:@[atlas, atlas2, atlas3, atlas4, atlas5, […]

你如何在没有抗锯齿的情况下扩展SKSpirteNode?

我试图缩放一个SKSpriteNode对象没有平滑/抗锯齿(我正在使用像素艺术,所以它看起来更好的像素化)。 我需要设置一个属性来执行此操作吗? 这是我用来渲染精灵的代码: SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"objects"]; SKTexture *f1 = [atlas textureNamed:@"hero_1.png"]; SKSpriteNode *hero = [SKSpriteNode spriteNodeWithTexture:f1]; [self addChild: hero]; hero.scale = 6.0f; 图像正确缩放但模糊/平滑。 这是hero_1.png 。

通用2D游戏资产和绝对节点定位

我有一个关于通用游戏资产和Sprite Kit (iOS 8+)中SKNodes 绝对定位的问题。 我将尝试通过一个例子来展示我的问题,如下所示 : 想象一下2D SKSpriteNode代表一个房子的自上而下的游戏 。 房子有多个代表椅子,桌子,沙发等的儿童SKSpriteNode 。 我有3个版本的房子资产: 1x – 200 x 200px (非视网膜iPad), 2x – 400 x 400px (视网膜iPhone和iPad), 3x – 600 x 600px (iPhone 6 Plus)。 重要 :子节点(椅子,桌子等)的位置在.plist文件中定义。 像这样的东西(JSON表示): children: [ { position = {20,20}; }, … ] 由于位置是以点为单位而不是以像素为单位的,因此根据设备的屏幕比例,所有的位置都可以按照预期定位 对于1x设备,位置保持{20,20} ,对于2x位置为{40,40} ,对于3x位置为{60,60} 。 问题 : 问题是,为了在所有设备上实现类似的外观和感觉, 200x200px和400x400px资产是适用于iPad的小型设备。 问题 […]

如何在SpriteKit场景编辑器中访问导航图的对象

我正在使用SpriteKit并通过xcode中的场景编辑器的帮助画一个场景。 根据SpriteKit,我们可以使用导航图来绘制path,我可以使用导航图来绘制path,但我无法在快速后端访问这个对象。 如何从场景中访问此导航图对象。

SKTexture和UIImage的scale属性

是否有任何理由为什么一个SKTexture似乎忽略了通过textureWithImage:构造图像的textureWithImage: 我有一个图像资源可用,“retina_image@2x.png” 当我尝试创build一个纹理,而首先创build一个UIImage: UIImage* image = [UIImage imageNamed:@"retina_image"]; SKTexture* texture_image = [SKTexture textureWithImage:image]; NSLog(@"image size %@, scale %f", NSStringFromCGSize(image.size), image.scale); NSLog(@"texture from image, size %@", NSStringFromCGSize(texture_image.size)); 我得到以下结果: image size {50, 50}, scale 2.000000 texture from image, size {100, 100} 虽然我期望得到 image size {50, 50}, scale 2.000000 texture from image, size {50, 50} 由于图像的大小(以点为单位)是50×50 当您直接使用资源构build纹理时,也是如此: SKTexture* […]