Tag: 精灵套件

如何将一个滑动手势添加到spritekit中的节点

我试图添加一个滑动手势到一个节点,以便当用户滑动它,它会离开屏幕,但我不断收到一个SIGABRT错误: `Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[fidget2.PlankScene swipedRight:]: unrecognized selector sent to instance 0x7ff4c3603e00'` 我不知道为什么这个错误是popup。 我确保节点在.sks文件中正确标记。 这是我的代码: import SpriteKit let plankName = "woodPlank" class PlankScene: SKScene { var plankWood : SKSpriteNode? override func didMove(to view: SKView) { plankWood = childNode(withName: "woodPlank") as? SKSpriteNode let swipeRight : UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedRight:")) […]

视差背景不重复

我的代码是重复移动的背景,它的意思是永远重复。 但是,当我模拟它,它会去一次,然后背景变灰。 这是我的代码: SKTexture* bgTexture = [SKTexture textureWithImageNamed:@"nightbackground"]; bgTexture.filteringMode = SKTextureFilteringNearest; SKAction* movebgSprite = [SKAction moveByX:-bgTexture.size.width*2 y:0 duration:0.1 * bgTexture.size.width*2]; SKAction* resetbgSprite = [SKAction moveByX:bgTexture.size.width*2 y:0 duration:0]; SKAction* movebgSpritesForever = [SKAction repeatActionForever:[SKAction sequence:@[movebgSprite, resetbgSprite]]]; for( int i = 0; i < 2 + self.frame.size.width / ( bgTexture.size.width * 2 ); ++i ) { SKSpriteNode* sprite […]

如何使用Swift绘制720个数据点

我目前正在写一个游戏杆的应用程序,我想显示我的激光雷达传感器的轮廓; 我正在使用精灵套件,但它是滞后的; 我假设它占用了太多的内存 我的激光雷达传感器返回给我360个数据点,其中每个度数表示它碰到物体(墙)的距离, 我正在初始化didMoveToView中的所有精灵套件节点,有没有更好的方法来实现这一点? 也许在初始化? 我正在创build720个精灵套件节点,因为360代表线条,360代表数据点(距离) 看起来好像我创build了太多的精灵套件节点(720+) 另外,我打算通过我的应用程序提供videostream。 Sprite Kit是最好的select吗? import Foundation import UIKit import SpriteKit class GameScene: SKScene { var visual = SKSpriteNode() let button = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 100, height: 50), cornerRadius: 10) var distances: [Int] = [2601, 2600, 33, 2608, 2601, 2594, 2625, 2633, 2637, 2651, 2656, 2666, […]

如何在SpriteKit中使用类似于物理的台球?

我是SpriteKit的新手,正在尝试制作台球游戏,但似乎没有正常工作。 球不会互相反弹或池提示。 我不确定我做错了什么。 这是一些球和池提示的示例代码。 任何帮助将不胜感激! class PoolTableScene: SKScene, SKPhysicsContactDelegate { struct PhysicsCatagory { static let None : UInt32 = 0 //0 static let PokeBall : UInt32 = 0b1 //1 static let PoolCue : UInt32 = 0b1000 //5 static let All : UInt32 = UInt32.max } let ballPoke = SKSpriteNode(imageNamed:"pokeBall") let cuePool = SKSpriteNode(imageNamed: "poolCue") override […]

精灵速度/速度在不同的设备上有所不同

我正在使用下面的代码将我的精灵从一个位置移动到另一个位置。 let screenScale: CGFloat = UIScreen.mainScreen().scale var travelSpeed: CGFloat = 20*screenScale let displacement = CGVector(dx: destination.x-enemy!.sprite.position.x, dy: destination.y-enemy!.sprite.position.y) let radius = sqrt(displacement.dx*displacement.dx+displacement.dy*displacement.dy) let normal = CGVector(dx: displacement.dx/radius, dy: displacement.dy/radius) let impulse = CGVector(dx: normal.dx*travelSpeed, dy: normal.dy*travelSpeed) let relativeVelocity = CGVector(dx:impulse.dx-enemy!.sprite.physicsBody!.velocity.dx, dy:impulse.dy-enemy!.sprite.physicsBody!.velocity.dy); enemy!.sprite.physicsBody!.velocity=CGVectorMake(enemy!.sprite.physicsBody!.velocity.dx+relativeVelocity.dx*rate, enemy!.sprite.physicsBody!.velocity.dy+relativeVelocity.dy*rate); 但是当我在我的iPhone 6S Plus上testing它时,精灵移动的速度比我的iPhone 5快得多。我认为下面的行适合不同的尺寸,因为我使用的是屏幕比例: var travelSpeed: CGFloat = 20*screenScale 还是我错过了什么?

滚动查看在某个点停止

嗨,我目前有一个水平的UIScrollView ,允许我在我的游戏中select一个字符,然后select它,但现在我有的问题是我试图让scrollview停止在精灵/字符在中间点屏幕,而不是让它停在任何地方。 我的UIScrollView有一个“可移动的节点”,其中包含多个页面,其中包含所有的精灵,如下所示: scrollViewHorizontal = CustomScrollView(frame: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height), scene: self, moveableNode: moveableNodeHorizontal, scrollDirection: .Horizontal) scrollViewHorizontal.contentSize = CGSizeMake(self.frame.size.width * 4, self.frame.size.height) // * 4 makes it three times as wide as screen view?.addSubview(scrollViewHorizontal) scrollViewHorizontal.hidden = true addChild(moveableNodeHorizontal) moveableNodeHorizontal.hidden = true moveableNodeHorizontal.zPosition = 100000 scrollViewHorizontal.setContentOffset(CGPoint(x: 0 + self.frame.size.width + self.frame.size.width * […]

当尝试产生一个节点时,“尝试添加一个已经有父节点的SKNode”错误

我一直得到的错误是这样的: Attemped to add a SKNode which already has a parent 。 我已经试图取出产卵function,它没有它的作品。 有人可以帮帮我吗 ? func spawnTrolls(){ let minValue = self.size.width / 10 let maxValue = self.size.width – 30 let spawnpoint = UInt32(maxValue – minValue) Troll.position = CGPointMake(CGFloat(arc4random_uniform(spawnpoint)), self.size.height) self.addChild(Troll) let action = SKAction.moveToY(-70, duration: 2) let actionDone = SKAction.removeFromParent() Troll.runAction(SKAction.sequence([action, actionDone])) Troll.physicsBody? = SKPhysicsBody(rectangleOfSize: […]

SpriteKit:根据方向改变纹理

我正在使用屏幕上的DPAD来移动我的angular色,但是我在根据方向传递我的小精灵时遇到了麻烦。 基本上我需要的是如果angular色正在向上移动,使用向上走animation。 向下移动,放下。 左边,左边和右边,使用正确的animation。 angular度是我真正遇到的麻烦。 这是我用来移动我的angular色的代码。 – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInNode:self]; SKNode *node = [self nodeAtPoint:location]; //if control pad touched if ([node.name isEqualToString:@"controlPadNode"]) { touchX = location.x +100; //adjust for anchor touchY = location.y +43; controlButtonDown = YES; } -(void)update:(CFTimeInterval)currentTime { if (controlButtonDown == […]

在游戏过程中添加另一个背景图片来改变背景

func createBackgrounds() { for i in 0…2 { let bg = SKSpriteNode(imageNamed: "BG Day") bg.name = "BG" bg.zPosition = 0; bg.anchorPoint = CGPoint(x: 0.5, y: 0.5) bg.position = CGPoint(x: CGFloat(i) * bg.size.width, y: 0) self.addChild(bg) } } 如果我想在BG Night 2分钟后添加另一个背景图像,我怎样才能在swift 2中编写代码?

两个相同节点之间的skphysicsbody碰撞

我创build了一个声明类SKShapeNode的类。 在它的init中,我设置了“SKPhysicsBody”属性。 在设置这些属性之前(将其保留为默认值),当一个球碰到另一个球时,受到碰触的两个球(例如:移动到不同的位置取决于碰撞位置)。 在设置了“physicsBody”属性之后,它将不再受到影响 – 一个球看起来比另一个球更高(如框架上的框架 – 隐藏它)。 我怎样才能设置这个属性? 我看着苹果文件,没有发现什么…这是我的代码: lass BallNode: SKShapeNode { var radius:CGFloat = 0 var color:UIColor? var strokeWidth:CGFloat = 0 private var _name:String? override init() { super.init() self.fillColor = ranColor() self.lineWidth = strokeWidth } convenience init(radius:CGFloat){ self.init(circleOfRadius: radius) self.radius = radius self.physicsBody = SKPhysicsBody.init(circleOfRadius: self.radius) self.physicsBody?.affectedByGravity = true print("ball physicsbody is […]