草庐IT

SkSpriteNode

全部标签

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

swift - SpriteKit - 获取 SKSpriteNode 的权重

我有一个应用程序,大盒子落在小红色盒子的顶部。我想知道红色小块何时达到一定重量(Xblock放在它上面)。我找不到红色block的权重属性。有什么建议么?编辑:只是为了澄清。从顶部掉落的盒子大小随机,从随机位置掉落。所以并没有真正的方法来跟踪落在红色方block顶部的东西。我需要一些方法来测量施加到红色block上的向下力 最佳答案 您可以通过以下方式计算每个节点的权重,然后将它们相加。redBox.PhysicsBody?.mass 关于swift-SpriteKit-获取SKSpri

swift - 场景大小内的节点位置

在我的SKScene中,我正在制作一个简单的太空射击游戏。无论在哪个iPhone上玩游戏,我如何才能确保我的敌人总是出现在屏幕尺寸内?换句话说,我如何计算场景大小的最大和最小X坐标,更重要的是,我如何根据运行游戏的iPhone了解当前场景大小? 最佳答案 不要根据iPhone型号调整场景大小,让Sprite-kit做这种工作:scene.scaleMode=SKSceneScaleMode.ResizeFillThesceneisnotscaledtomatchtheview.Instead,thesceneisautomatica

ios - 设置最低滚动速度

我有一个球,我将它射向空中:它是这样初始化的:funcinitBallNode(){//TODO:CreateballnodeballNode=SKSpriteNode(imageNamed:"Ball1")//CreateaballballNode.zPosition=ZPositions.ballletoffsetFromCorner:CGFloat=20//Offsetfrombottom-leftofscreenballNode.position=CGPoint(x:frame.minX+ballNode.size.width/2+offsetFromCorner,y:fram

swift - 如何在没有 SKTexture 的情况下更改 didBeginContact 中的 SKSpriteNode 大小和颜色?

我一直在使用SKTexture按以下方式在didBeginContact中更改SKSpriteNode的颜色和大小。iffirstBody.categoryBitMask==spriteCategory&&secondBody.categoryBitMask==enemyCategory{varnewSprite=firstBody.nodeletnewImage=SKTexture(imageNamed:"newSprite.png")(newSpriteas?SKSpriteNode)?.size=newImage.size()//magicoldToNewSpriteAction

swift - SpriteKit 许多来自同一图像的节点 : Load Separately or Duplicate?

我正在用SpriteKit编写一个游戏,并且正在编写一个部分,其中“关卡”是从文本文件中加载的,在文本文件中用“x”标记的每个位置放置一个墙节点。但是,如果我知道会有很多节点,并且它们都是从同一个“wall.png”文件加载的,那么加载一次图像然后在每次需要时复制对象是否更有效,还是每次只加载图像?forlineinlines{forletterinline{ifletter=="x"{letwall=SKSpriteNode(imageNamed:"wall")self.addChild(wall)}else{...}}}对比letwall=SKSpriteNode(imageNam

Swift SpriteNode 初始角度

我试图将Sprite的初始角度设置为90度。我不想调用Action,有没有办法像设置位置一样设置Sprite的角度参数? 最佳答案 z旋转您可以使用接受辐射的SKNode的zRotation属性度数自辐射度There's一个有用的扩展extensionInt{vardegreesToRadians:Double{returnDouble(self)*M_PI/180}varradiansToDegrees:Double{returnDouble(self)*180/M_PI}}sprite.zRotation=CGFloat(90.

ios - 从 SKTexture 创建的 SKSpriteNode(数据 :size:) issues with Alpha (Opacity)

我在从pixelData创建SKSpriteNode时遇到问题。下面是我的代码。varpixelData:[UInt32]=[UInt32](count:256,repeatedValue:0xff0000ff)pixelData.appendContentsOf([UInt32](count:256,repeatedValue:0xff00ff00))pixelData.appendContentsOf([UInt32](count:256,repeatedValue:0xffff0000))pixelData.appendContentsOf([UInt32](count:256,

swift - 使用场景编辑器获取 SKSpriteNode 的 userData

我在场景编辑器中设置我的SKSpriteNode的用户数据:然后我尝试获取它,使用:letsprite:SKSpriteNode=self.childNode(withName:"sprite")as?SKSpriteNodeletnumero:Int=sprite.userdata?.valueForKey("numero")as!Int但我得到了nil值:“fatalerror:在展开可选值时意外发现nil”我还尝试使用以下方法初始化userData:sprite.userData?=NSMutableDictionary()但同样的结果... 最佳答案