草庐IT

Sprite-kit

全部标签

swift - Scene Kit Swift 节点多次旋转

在带有Swift的SceneKit中,我只能进行一次旋转。我想在每次用户点击屏幕时沿z轴旋转相机。funchandleTap(){println("start")SCNTransaction.begin()SCNTransaction.setAnimationDuration(1.0)SCNTransaction.setCompletionBlock(){println("done")}_cameraNode.rotation=SCNVector4Make(0,0,1,CFloat(-M_PI_4)*0.5)SCNTransaction.commit()}但是,我想在每次触摸时保持旋转

ios - Swift - 如何在移动到另一个场景时从场景中删除滑动手势?

所以我的游戏使用滑动手势,在我的didMoveToView()函数中我初始化了这些手势:letswipeRight=UISwipeGestureRecognizer()swipeRight.direction=UISwipeGestureRecognizerDirection.Rightself.view?.addGestureRecognizer(swipeRight)letswipeLeft=UISwipeGestureRecognizer()swipeLeft.direction=UISwipeGestureRecognizerDirection.Leftself.view?.a

swift - Swift 中的随机值

我试图获得一个介于0和我的屏幕尺寸之间的值。所以我这样做了:letsizeX=Int(CGRectGetMaxX(self.frame))letsizeY=Int(CGRectGetMaxY(self.frame))varrandomX=CGFloat(arc4random())%sizeXvarrandomY=CGFloat(arc4random())%sizeYself.touchButton.position=CGPointMake(randomX,randomY)我有这个错误:找不到接受提供的参数的“%”的重载我需要这个来随机化SkSpriteNode的位置,也许有更好的解决方

ios - 试图添加一个已经有父错误的 SKNode

我在尝试运行我的游戏时遇到错误:“试图添加一个已经有父节点的SKNode”。如果我在本地将SKSpriteNode添加到函数中,它运行良好。但是当我尝试全局声明它时,我得到了那个错误。解决此错误的任何帮助都会很棒。我认为它与self.bee.removeFromParent()有关,但我无法让它工作。让蜜蜂=SKSpriteNode(imageNamed:"蜜蜂")runAction(SKAction.repeatActionForever(SKAction.sequence([SKAction.runBlock(addBee),SKAction.waitForDuration(0.5

swift - didBeginContact 未调用

我正在制作一个需要我的spriteNodes发生碰撞的游戏。我遵循了一个教程,但它对我不起作用。当我运行我的游戏并且两个对象发生碰撞时,输出监视器中没有println("beginContact"),因此没有调用didBeginContact函数。overrideinit(size:CGSize){super.init(size:size)player.planeSprite=SKSpriteNode(imageNamed:"plane5")player.planeSprite.physicsBody?=SKPhysicsBody(rectangleOfSize:player.plan

ios - SpriteKit touchesMoved 在 SKSpritenode 的子类中使用时不稳定

我将SKSpritenode(在Swift中)子类化以创建彩色block,然后可以在场景中拖动这些block。子类是SoundNode。importSpriteKitclassSoundNode:SKSpriteNode{init(){super.init(texture:nil,color:UIColor.blue,size:CGSize(width:100,height:100))self.isUserInteractionEnabled=true}requiredinit?(coderaDecoder:NSCoder){fatalError("init(coder:)hasnot

ios - 忽略子类 SKSpriteNode 触摸事件

所以我正在为此烦恼,我正在使用SpriteKit和Swift开发一个小游戏,我已经将SKSpriteNode子类化,添加了一些额外的属性并覆盖了touchesBegan(),如此。classDigit:SKSpriteNode{varuserEntered=0varindex=0...(gameproperties)overridefunctouchesBegan(touches:NSSet,withEventevent:UIEvent){println("Digit.touchesBegan()"...(gamelogic)}overridefunctouchesMoved(touc

ios - 无法在 Xcode 6 Playground 中使用 SpriteKit

我正在尝试像这样在Xcode6Playground中使用SpriteKit:importUIKitimportSpriteKitimportXCPlaygroundvarspriteView=SKView(frame:CGRectMake(0,0,1334,650))spriteView.backgroundColor=UIColor(red:0.167,green:0.165,blue:0.164,alpha:1.0)letrootScene=SKScene()letrect=SKShapeNode(rect:CGRectMake(10,10,100,100))rect.fillCo

ios - SKLabelNode 文本消失使用 iOS 7.1

我编写了一个名为updateLabel的函数来计算我收集的硬币随着时间的推移。我使用NSTimer调用该函数以获得计数效果。使用iOS8一切都很好,但是一旦我使用iOS7.1调用该函数,我的标签就会变成空白...如果我打印出Label.text,我会得到正确的数字,但它只是不显示。即使是声音“coinSound”也能正常工作。scoreLabel=SKLabelNode()scoreLabel.text="0"self.addChild(scoreLabel)//showsupandworkswith"0"self.timer=NSTimer.scheduledTimerWithTim

ios - 在 SpriteKit 的不同屏幕上为节点大小定义变量的最佳方法

我正在用SpriteKit制作游戏。对于将要在我的场景中使用的不同节点,我有不同的类。我需要让我的游戏具有通用性,以便它适应每个屏幕。定义我将在不同类和主场景中使用的不同变量的最佳方法是什么。 最佳答案 然后初始化您的节点,您可以创建您的worldSKNode参数,然后访问您的world.frame.size。classNodeClass:SKSpriteNode{init(world:SKNode){super.init(texture:nil,color:UIColor.clearColor(),size:CGSizeMake(